joshua
joshua

Reputation: 684

AS#3 loading SWF Multiple

Im loading multiple SWF of the same file Example:

      var movies:Array = new Array ("Symbols/00.swf","Symbols/00.swf","Symbols/00.swf");

My loading method works fine, below im using:

var perc:int = (event.bytesLoaded / event.bytesTotal) * 100;
Loading.text = "loading " +perc + "%";

The Problem im having is the the loading text is at %100 after iv downloaded one item from the Movies:Array.

This would be happening because the remainder files are already in the catch.

The question is: How would I be able to slow this loading text to determine if all the items are ready.Basically the problem is that the loading text saids complete but all my other files are not ready yet...

Upvotes: 0

Views: 377

Answers (1)

Vesper
Vesper

Reputation: 18757

First, why do you ever load one SWF multiple times? You can use the following trick: How to display multiple instances of loaded SWF. And second, you are using your Loader object to load one SWF at a time, and its progress will be related to that single SWF. So, you first load all unique SWFs and store their Loader references somewhere, in order to instantiate more of those if you need to, and second, you are to collect total percentage from progress event listener. The latter is slightly complicated, because you are most likely using a single progress event listener for all the loaders. You, for example, can do something like this:

public static var ALL_LOADERS:Object;
public static var PROGRESS_DATA:Object; // we need associative arrays here
public static var BYTES_LOADED:int=0;
public static var TOTAL_BYTES:int=0;

public static function RegisterLoader(path:String,loader:Loader):void {
    if (!ALL_LOADERS) ALL_LOADERS=new Object();
    if (!PROGRESS_DATA) PROGRESS_DATA=new Object();
    ALL_LOADERS[path]=loader;
    PROGRESS_DATA[loader]=new Object();
    PROGRESS_DATA[loader].bytesLoaded=0;
    PROGRESS_DATA[loader].bytesTotal=-1;
}

// now a listener
public static function progressListener(e:Event):void {
    var l:Loader=e.target as Loader;
    if (!l) return; // that wasn't a loader that sent the event. Uh oh
    var plo:Object=PROGRESS_DATA[l];
    if (!plo) return; // unregistered loader. Ignore
    if (plo.bytesTotal<0) {
        plo.bytesTotal=e.bytesTotal;
        TOTAL_BYTES+=e.bytesTotal;
    }
    var pbl:int=plo.bytesLoaded;
    plo.bytesLoaded=e.bytesLoaded;
    LOADED_BYTES+=(e.bytesLoaded-pbl);
    var perc:int = (LOADED_BYTES / TOTAL_BYTES) * 100;
    Loading.text = "loading " +perc + "%";
}

Note, as the loading process is designed to be run only once, all initialization is made once, and this code does not have error handling - you can, however, write it yourself.

Upvotes: 1

Related Questions