SpaceA
SpaceA

Reputation: 23

Unload multiple SWF problem in ActionScript 3.0

i have problem with memory usage in flash, I successfully unload and remove loaded SWF's from the stage but i can't remove loaded memory and also the fps is dropping down from 30 to 18.

  1. How i load the SWF in to memory

    • I have swfUrlArray Array where i keep the SWF names (addreses ex. "intro.swf").
    • I have swfModules Dictonary where i keep the loaded SWF's.

    I loading them like this:

    mLoader = new Loader();
    var mRequest:URLRequest = new URLRequest(url);
    mLoader.load(mRequest);
    mLoader.x = pozX;
    mLoader.y = pozY;
    swfModules[url] = mLoader;
    swfUrlArray.push(url);
    currentLoaded = url;
    addChild(mLoader);
    
  2. Removing the SWF's in the loop

    for(var i=0; i < swfUrlArray.length; i++) {
        if(swfModules[swfUrlArray[i]] != null) {
            swfModules[swfUrlArray[i]].unloadAndStop();
            removeChild(swfModules[swfUrlArray[i]]);
        }
        swfUrlArray=[];
    }
    

    What i suspect here is that loop is too fast to flash to unload the SWF's memory for all files at same time. Please any suggestions or ides for this problem.


Upvotes: 0

Views: 419

Answers (2)

You clear the swfUrlArray INSIDE your for loop. So it will only unloadAndStop the first, find that the length of the array is 0 and stop.

Modified code:

for(var i=0; i < swfUrlArray.length; i++) {
    if(swfModules[swfUrlArray[i]] != null) {
        swfModules[swfUrlArray[i]].unloadAndStop();
        removeChild(swfModules[swfUrlArray[i]]);
    }
}
swfUrlArray=[];

And do what @alxx says about removing the swf reference from the dictionary.

Upvotes: 1

alxx
alxx

Reputation: 9897

Is swfModules a Dictionary? It seems it still holds reference for loaded swf. Use delete swfModules[url] to remove item from Dictionary.

Upvotes: 0

Related Questions