In the earlier section "Accessing the Loaded Asset," we learned that when a
.swf file loads another .swf file, all visual assets and
programmatic objects on the loaded .swf file's first frame are available as
soon as the
occurs. Hence, code in an
Event.INIT event listener can immediately
operate on those assets and objects. However, code within an
Event.INIT event listener cannot operate on
assets and objects created on subsequent frames in the loaded
Any code wishing to access assets and objects created on or after the second frame of a loaded .swf file must first verify that those assets and objects exist. There are two ways to verify that assets and objects in a loaded .swf file exist:
In the accessing .swf file, use a Timer object to poll for the existence of the asset or object.
In the accessing .swf file, register for a custom event that is dispatched by the loaded .swf file when the asset or object becomes available.
Let's consider an example for each of the preceding techniques.
We'll again use the scenario of Main.swf loading Module.swf from the previous section.
Suppose Module.swf has a script
on the second frame of its main timeline that creates a TextField object,
t. Main.swf loads Module.swf and wishes to access
t. Here's the timeline script in Module.swf:
stop(); var t:TextField = new TextField(); t.text = "hello"; addChild(t);
Example 28-10 shows how Main.swf loads Module.swf and then polls for the existence ...