Posts Tagged ‘stage’

Comment icon 0
Event.ADDED_TO_STAGE

Note to self: when loading a SWF into another Flash movie, the SWF can’t access any properties of the parent stage until Event.ADDED_TO_STAGE has been triggered. It doesn’t automatically recognize when it has been added to a stage. So remember to put the following at the top of the movie being loaded:

MovieClip(root).addEventListener(Event.ADDED_TO_STAGE, initClip);

…where initClip is a function that will be executed once the movie has been added. This can contain any code that makes use of stage properties, including adding event listeners that require access to stage properties.

The MovieClip(root) part of the code means grab the root of the movie being loaded and cast it as a MovieClip. (I think.)

Further note to self: the stage of the loaded movie no longer exists once it’s loaded; it becomes the stage of the container movie.

This post here basically summarizes it.

EDIT: This also applies to custom-written AS classes that require access to stage properties. If an instance of that class doesn’t exist on stage yet, any code in the class that calls on stage properties will be confused and yell at you.