Updated: April 30th, 2009

GotoClip. A solution for Error #1009, gotoAndStop, gotoAndPlay and targeting children MovieClips.

iconApril 30th, 2009

One of the differences between ActionScript 2.0 and 3.0 is the behavior of MovieClip timelines and code targeting display list children. For example in AS 2.0 it was possible to call gotoAndStop or gotoAndPlay and then directly manipulate MovieClips at the targeted frame.
gotoAndStop(25);
child_mc._rotation = 25;
In AS 3.0 calling the equivalent code
gotoAndStop(25);
child_mc.rotation = 25;
will yield a runtime error such as this.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MyFla_fla::MainTimeline/frame1()

GotoClip is a class that restores some of the AS 2.0 timeline functionality to AS 3.0 MovieClips. It will allow calls to be made like this
gotoAndStop(25);
var child:MovieClip = getChildByName("child_mc") as MovieClip;
child.rotation = 25;
while avoiding runtime errors. The class makes it possible to target a display list child MovieClip anywhere on the timeline after a gotoAndStop, or gotoAndPlay call. Then within the same code block properties can be set on the child MovieClip. During runtime the GotoClip class behaves as a proxy to store the commands made to the child MovieClip. GotoClip then applies those commands when the Flash Player has successfully drawn the child MovieClip to the stage, thereby avoiding the typical runtime Error #1009.

GotoClip resides within a small ActionScript library I created called the AS3 Display List Library. The library resides on Google Code. It includes a Wiki and the downloads section includes samples with source code and a swc which can be used for compiling with Flash and Flex projects.

3 Responses to “GotoClip. A solution for Error #1009, gotoAndStop, gotoAndPlay and targeting children MovieClips.”

  1. Hasnt this changed in FP10?

    In FP10 it waits till the gotoAndStop() is executed an the frame is fully rendered?

  2. Just tested this out in CS4 Version 10.0 of the IDE. And I still get the same error. For example if I have a frame script on frame 1 and try to change a property of a MovieClip that first appears on Frame 40, I will still get an Error #1009 if my frame 1 frame script looks like this:
    gotoAndStop(40);
    frame40_mc.alpha = 0.5;

  3. Thanks for you post! I was loosing my head on why I’m getting this error every time I call gotoAndStop on my custom movie clip I had just instantiated.
    Flash really looses the reference to the object when you call gotoAndStop, or gotoAndPlay. You need to instantiate your object, make all changes necessary and finally change it’s frame if needed, otherwise you’ll need to find you recently instantiated object on the stage children, if you had added it to it. That’s messed up!

Leave a Reply

The Author

Johannes Tacskovics
ECMAScript Developer

Portrait of Johannes Tacskovics

On front-end software engineering this is the blog of Johannes Tacskovics, a Los Angeles based ECMAScript Developer. This blog is focused on object oriented software development for the web.

Article Categories

Article Archives

Meta