O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Accessing Assets in Multiframe .swf Files

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 Event.INIT event 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 .swf file.

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required