How to load an external SWF?
Most Flash-based virtual worlds (or social games as generally called) allows customization of characters. This means extra work for the artist to create a wide variety of eyes, nose, ears, and mouth — not to mention: hairs, tattoos, masks/helms, and if applicable, armors and weapons.
If all art assets are included inside the main SWF file, it will take a little longer for the game to load. To keep the main SWF file size as low as possible, other art assets are loaded dynamically.
Below is a sample ActionScript 3 code to load external SWF.
package {
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
public class Main extends MovieClip {
public function Main() {
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
public function onAddedToStage(e:Event):void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loader_onProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_onComplete);
loader.load( new URLRequest("SomeExternalAsset.swf") );
}
private function loader_onComplete(e:Event):void {
addChild(e.currentTarget.content);
}
private function loader_onProgress(pe:ProgressEvent):void {
var loaded:Number = Math.ceil(pe.bytesLoaded / pe.bytesTotal) * 100;
}
}
}








One Response. Yay!
How to load an external SWF?
July 24th, 2010
You must be logged in to post a comment.