0

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...

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

the reason iv loaded multiple because it was easier there is actually 300 items in the array to be loaded , but all duplicates.10 swf movies * 30..= lol your probably right i should handle this better, i give your option a try
i found an easy way to duplicate a class, or external swf it worked well, its about 4 lines of code..
Do you mean utilizing getQualifiedClassName(source) then getDefinitionByName(sourceString) then instantiating? It's doable, right, but if your class does not require customization past creation.
if (symbolsArray[cou1] == "slot" + countSymbols) { var ClipSWF:Class = _swfClipsArr[countSymbols].constructor; var ClipSWF_copy:MovieClip = new ClipSWF(); SLOTS[cou1].addChild(ClipSWF_copy); TempSWFS.push(ClipSWF_copy); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.