Skip to main content
Inspiring
October 15, 2010
Frage

Preloader for an external .swf loaded via the Loader Class

  • October 15, 2010
  • 1 Antwort
  • 473 Ansichten

Hi everyone,

I'm hoping to implement a preloader on a main.swf that measures the bytes etc loaded in an external.swf.

My two concerns are that 1) this just isn't possible? 2) I can't have multiple preloaders on the main.swf, which I would if I used one for the external .swf

I intend to try and explain this in the best way I can what I have done so far, as I personally feel this is quite a complex task.

Here's the basics:

1) I have an external .swf file, being loaded, using the following Action Script (3), in what I shall call, main.swf:

//---loader---

var swfLoader:Loader = new Loader();

addChild(swfLoader);

var swfURL:URLRequest = new URLRequest("nameofswftobeloaded.swf");

swfLoader.load(swfURL);

function loadHandler (event:Event){

var thumbsPanel:MovieClip = event.target.content;

addChild(thumbsPanel);

This works fine.

The Action Script I use after this simply allows me to control the external .swf from the main .swf so isn't necessary..

I finish the loader, with this: "swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadHandler);"

So, this all works fine.

However, as the external .swf contains images, it doesn't load instantly.

I therefore need some kind of preloader to show how much of the external .swf is loaded.

However, I tried placing this in the external .swf itself and it failed miserably - for some reason it basically didn't preload and the completed phase of the preloader just appeared..

If you have any ideas how I could solve this problem, I'd hugely appreciate it.

Thanks for your help in advance!

Dieses Thema wurde für Antworten geschlossen.

1 Antwort

October 16, 2010

You simply need to add a progress event listener like:

swfLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);

And then you can get all the info you need to update a preloader:

function progressHandler(e:ProgressEvent):void

{

     trace(e.bytesLoaded / e.bytesTotal * 100);

}