开发者

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜