05.08.08

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

Posted in Error, Error, Flash, Flex, errors at 9:20 pm by Curtis J. Morley

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

2 Comments »

  1. shauna said,

    June 24, 2008 at 4:30 pm

    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.

  2. Curtis J. Morley said,

    June 25, 2008 at 6:55 am

    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

Leave a Comment