Flash / Flex 3 Error #1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:DisplayObject.

ActionScript 3 Error #1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:DisplayObject.

ActionScript 3 Error #1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:DisplayObjectContainer.

ActionScript 3 Error #1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:Stage.

Description:
AS3 error 1061 will pop up when you trying to referencee an object from within a function that receives an Event. When you do this it will reference the DisplayObject or if you call out to this.parent rather than event.target.parent it will reference the DisplayObjectContainer which doesn’t have a lot of methods with it.

Fix:
One solution to solve Flex/Flash Error 1061 is to make sure that you are using the event that is passed as the target by using

Bad Code 1:

getStarted_btn.addEventListener(MouseEvent.MOUSE_UP,gotoFrame10 );

function gotoFrame10 (e:MouseEvent)
{
this.parent.gotoAndStop(10);
}

Good Code 1:

getStarted_btn.addEventListener(MouseEvent.MOUSE_UP, gotoFrame10);

function gotoFrame10 (e:MouseEvent)
{
e.target.parent.gotoAndStop(10);
}

This should help you resolve Flash / Flex Error #1061

Thanks and as always Happy Flashing

Curtis J. Morley

16 thoughts on “Flash / Flex 3 Error #1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:DisplayObject.

  1. I’ve tried to fix this error, but I don’t completely understand what the **** it means… this is the code, if that helps

    public var string = string1;
    public var wordsArray = string1
    public function convert():void{
    wordsArray = string1.split(” “)
    }
    ]]>

    I really appreciate the effort that you’ve gone to to list all the errors, by number and how to solve them…It’s given me 10 years of my life back 😀

  2. You can also run across 1061 error if you are accidentally refer to a class instead of an instance of a class, like when using a singleton. Example:

    public class MySingleton {
    myMethod(){blah}

    }

    In code.
    MySingleton.myMethod(); //return error 1061

    Can be cured with MySingleton.getIntance().myMethod();// where getIntance returns the instantiated copy of the class.

  3. Brilliant! Totally forgot about using the event target as a means of targeting the parent.

    I was using the casting method to achieve the same result but felt that it wasn’t the right way to do things.

    ie. MovieClip(parent).gotoAndStop(10) or
    var mc:MovieClip = parent as MovieClip;
    mc.gotoAndStop(10);

  4. Hi!
    I also get the error 1061 When I try to remove an item from the stage with removeChild();
    would you please show some sample code for this? I saw that you responded to another comment, but that guy’s code has been removed.
    In my kekeke document I’m trying to accomplish the “kekeke” to lift up the green item when it touches it.

    I Think that what I’m trying to do is: when it touches the green item, the green item will disappear and the kekeke will change appearences

    kekeke4-lyfta-pryl.fla

  5. I started working with flash earlier this year so try to be patient with me.I am working on a little project at school and I can’t seem to get a button to work. Here is the code:

    nextLevel_btn.addEventListener(MouseEvent.CLICK, onNextLevelClick);

    function onNextLevelClick(e:MouseEvent)
    {
    e.target.parent.gotoAndStop(2);
    }

    thanks for your help

  6. Thanks for posting this tidbit, Curtis.

    Just now bridging from AS2 to 3, and I’ve brought a lot of bad habits along.

  7. Thank you so much for posting this! Such an easy fix but could have taken me who knows how long to figure out on my own. Thank you!!!

  8. I am trying a similar button code as you have mentioned, but it throws the 1061 error right at 1st line:

    getStarted_btn.addEventListener(MouseEvent.MOUSE_UP,gotoFrame10 );

    +–+–+
    1061: Call to a possibly undefined method addEventListner through a reference with static type fl.controls:Button.
    +–+–+

    I am at my wits end. Any clue?

  9. Shauna,

    I took a look at your code. It appears that you want to add and remove a child to a newly created movieClip To solve this you need to target the instance “newempty1” rather than the class “empty1”. empty1 is the class not the instance. addChild and removeChild work on instances because they are part of the displayObject. Classes are not part of the display object and therefore will give you AS3 Error 1061. Pay attention to lines 15,16, 30, 32, 47, and 48 in the code I sent back to you. I added newempty1 and newempty2 to the code so that it would recognize the instance rather than the class. I didn’t get the empty1 and empty2 Classes so I couldn’t see if this worked but would be happy to take a look. You will need to target the removal of the movieClip properly on lines 30 and 47 or else you will get ActionScript Error 1136 Also the tweens on line 42 and 43 need a different name or else you will get ActionScript Error 3596

    Thanks,

    Curtis J. Morley

  10. Trying to learn AS3 by converting a simple AS2 project into AS3 with little success. And I need some advice from an expert such as yourself.

    I am getting all 1061 errors when I try to publish my code. It has something to do with the addChild and removeChild code I am using to replace the attachMovie and removeMovieClip code from AS2. Would you be willing to take a quick look at my code? You can download it here.

Comments are closed.