开发者

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 th开发者_开发百科e 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.



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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜