Loading SWFs in AIR- Important Classes for games in AS 3.0

December 22nd, 2011 by aabhaanjan

images

[xml]
package
{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;

/**
* …
* @description : This class is for loading SWFs in AIR for Mobile app etc.
* @author Aava Rani
*/
public class SWFLoader extends MovieClip
{
private var loader:Loader;
public function SWFLoader():void {
initLoader(‘test.swf’)
}

private function initLoader(__path:String):void {
loader = new Loader();
var appDomain:ApplicationDomain = new ApplicationDomain();
var context:LoaderContext = new LoaderContext(false, appDomain);
loader.load(new URLRequest(__path), context);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
}
private function loaded(event:Event):void
{
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loaded);
addChild(loader.content);
}

}
}
[/xml]