开发者

Preloader to load external SWF without PROGRESS and COMPLETE events

开发者 https://www.devze.com 2023-03-08 14:13 出处:网络
I have created the following preloader saved as \"preloader.swf\" that loads an external SWF file as follows:

I have created the following preloader saved as "preloader.swf" that loads an external SWF file as follows:

var req:URLRequest = new URLRequest("main.swf");
var loader:Loader = new Loader();
loader.load(req);

loader.contentLoaderInfo.addEventListener(Event.OPEN, showPreloader);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, showContent);

var preloader:Preloader = new Preloader();

function showPreloader(event:Event):void 
{
    addChild(preloader);
    preloader.x = (stage.stageWidth / 2) - (preloader.width / 2);
    preloader.y = (stage.stageHeight / 2) - (preloader.height / 2);
}

function showProgress(event:ProgressEvent):void 
{
    var percent:Number = event.bytesLoaded / event.bytesTotal;
    preloader.percentage.text = Math.round(percent * 100)开发者_Go百科 + "%";
    preloader.bar.width = 300 * percent;
}

function showContent(event:Event):void 
{
    removeChild(preloader);
    addChild(loader);
}

I was reading to try avoid the PROGRESS and COMPLETE events since these events don't work 100% of the time.

Now my question is this: is there a way of how I can go about to have the same functionality of loading an external SWF file (as above) but WITHOUT using the PROGRESS and COMPLETE events?

If so, can anyone suggest me what coding to add/change?

Thanks.


HAve you tried with a Timer? You check at every interval is the SWF is loaded entirely or not.

However , PROGRESS and COMPLETE events should always work. What's not working in your project?

0

精彩评论

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