简体   繁体   中英

Preloader to load external SWF without PROGRESS and COMPLETE events

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) + "%";
    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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM