AS3 preloader for external swf file
Question! Whats the best way to have a preloader for loading an external swf file. I wrote this for the actu开发者_JAVA百科al operation of the button
function btnClick(event:MouseEvent):void
{
removeChild(loader);
var newSWFRequest:URLRequest=new URLRequest("swf/" + event.target.name + ".swf");
loader.load(newSWFRequest);
loader.x = Xpos;
loader.y = Ypos;
addChildAt(loader, numChildren);
}
Any help would be awesome.
Just add a progress event listener and place your code in the handler.
function btnClick(event:MouseEvent):void {
var newSWFRequest:URLRequest=new URLRequest("swf/" + event.target.name + ".swf");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
loader.load(newSWFRequest);
loader.x = Xpos;
loader.y = Ypos;
addChildAt(loader, numChildren);
}
function completeHandler(e:Event):void {
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeHandler);
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressHandler);
trace("load complete");
}
function progressHandler(e:ProgressEvent):void {
var perc:Number = Math.round((e.bytesLoaded/e.bytesTotal)*100)/100;
trace(perc);
}
精彩评论