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.
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
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
Event.INIT event listener in
private function initListener ...