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

Instantiating a Runtime-Loaded Asset

The technique for creating a new instance of a runtime-loaded asset varies according to whether that asset is a .swf file or a bitmap. The following two sections describe the instantiation process for both types of assets.

Instantiating a Loaded .swf File

To create a new instance of a loaded .swf file, we must first obtain a reference to that .swf file's main class. Once the class reference is obtained, we use the new operator to create the instance. There are two general approaches for obtaining a reference to a loaded .swf file's main class:

  • Retrieve a direct reference to the class using the source-path, library-path, or external-library-path techniques covered in the earlier section "Compile-Time Type-Checking for Runtime-Loaded Assets."

  • Retrieve a reference to the class using the ApplicationDomain class's instance method getDefinition( ).

Let's look at examples for both approaches by returning to the "Main.swf loads Module.swf " scenario from earlier sections.

Suppose we want to make a new instance of Module.swf in Main.swf. We first make the Module class directly available to Main.swf by following the source-path technique, the library-path technique, or the external-library-path technique covered earlier. Reviewing what we've already learned, recall that once the Module class is available to Main.swf, we can reference it directly, as shown in the cast operation excerpted from the Event.INIT event listener in Example 28-9:

private function initListener ...

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