import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.errors.IOError;
var url = "...";
var loader:Loader = new Loader();
var urlreq:URLRequest = new URLRequest(url);
//add listeners:
loader.contentLoaderInfo.addEventListener(Event.INI, handleLoadIni);//This is called in the first frame of the movie not when the whole movie is loaded
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoadComplete);//Called when the whole movie is done loaded
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError);//Called if the movie fails to load
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, handleProgress); //Used for preloader
//load
loader.load(urlreq);
private function handleLoadComplete(event:Event):void {
var loader = event.target.loader; //reference to the loader object
var content = event.target.content; //reference to the swf
this.addChild(content); //adds the movie to the stage
}
Tuesday, June 9, 2009
How to load a swf in AS3
Here is how to load an external SWF or JPG file
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment