Flash Script
none none none
none Loading external SWF files

Summary
Loading swf files in actionscript 3
It is almost exactly the same as loading images.
The simplest way to manage is adding the loader to the stage and load the swf file
(see code below)


Code
var loadernode:Loader = new Loader();
addChild(loadernode);
loadernode.load(new URLRequest( "http://somesite.com/flash.swf" ) );


Executing methods in the swf file
Accessing and executing methods INSIDE the loaded swf file.

Here is a code snippet below:
Once the swf file has been loaded (initialized), we can now try to access it's class definitions.
We create a class object and then invoke it to create an instance variable

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
loader.load(new URLRequest("flash.swf"));

function onInit(e:Event):void
{
var mc:MovieClip = MovieClip(LoaderInfo(e.target).content);
var cls:Class = mc.loaderInfo.applicationDomain.getDefinition("ClassName") as Class;
var myinstance:* = new cls();
}


References:
Failure to unload. Flash Player 9 dirty little secret.
Loading an external SWF file

none
none none none







History Licensing & Pricing Privacy Policy Contact Us
Frequently Asked Questions