as3 load the main scenario the use of external libraries
filed in Flash as on Nov.19, 2009
The main module main.swf, is called the module lib.swf,
lib.fla of the document class Lib.as, assume that the defined module Module0.as, Module1.as
package com (
import com.Module1;
import com.Module2; / / import module
public class Lib extends MovieClip (
private var module1: Module1;
private var modlue2: Module2; / / To define a variable of this type
)
)
In the main document class in the
function init (): void (
loader = new Loader;
loader.contentLoaderInfo.addEventListener ( “complete”, getRefer);
loader.load (new URLRequest ( “lib.swf”));
)
function getRefer (e: Event): void (
var module0: Class = loader.contentLoaderInfo.applicationDomain.getDefinition ( “com.Module”) as Class;
/ / Other similar can be Lib has been declared before the class: Lib, Module0, Module1 …
/ / getDefinition () parameter to include the package name of class being loaded
/ / new module0 ();
)
This is the as3 reflection, you can find out more online under the keywords for example;
As for the components to be loaded Lib.swf the same token, the component linkage to export for ActionScript defines a Class class name such as Test_mc
Load it as above, class loading
function getRefer () (
…
var test_mc: Class = loader.contentLoaderInfo.applicationDomain.getDefinition ( “Test_mc”) as Class;
/ / Here getDefinition () parameters do not need to include package name
addChild (new test_mc);
)
Leave a Reply