ActionScript 3.0, Adobe Flex

Adobe Flex : Dynamically loading classes at runtime

Loading classes dynamically is a powerful and very useful technique.
Using the SWFLoader in the controls package makes doing this straightforward …

var libraryLoader:SWFLoader = new SWFLoader();
libraryLoader.source = “Library.swf”;

if( libraryLoader.loaderContext.applicationDomain.hasDefinition( “Foo” ) )
{
var FooClass:Class = libraryLoader.loaderContext.applicationDomain.getDefinition( “Foo” ) as Class;
var fooInstance:* = new FooClass();
}

An interesting aspect with this technique is the theoretical ability to have several classes with an equal fully qualified name in the same application instance as long as they are loaded from different applicationdomains. I cant foresee what eventually will happen in the case of a casting collision, but I intend to find out as soon as I have 15 minutes to spend.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s