Search code examples
flashactionscript-3loader

Trouble with loader.close


Can anybody explain, why loader.close didn't work? Btw i know about loading files from server thing.

for (var p:Number = 0; p < itemsOnPage; p++) 
{
    if (itterationStep != SqlRec.itemsArray.length) 
    {
        thumbImgLoader = new Loader();
        var imgName:String = SqlRec.itemsArray[itterationStep]["img"];
        thumbImgLoader.load(new URLRequest(GetXMLprefs.thumbsPath + imgName));
        thumbLoadersArray.push(thumbImgLoader);
        ...
    }
}

/////

if (ItemsBuilder.thumbLoadersArray) 
{
    if(ItemsBuilder.thumbLoadersArray.length > 0)
    {
        for (var i:Number = 0; i < ItemsBuilder.thumbLoadersArray.length; i++) 
        {
            try 
            {
                var obj:Loader = new Loader();
                obj = ItemsBuilder.thumbLoadersArray[i];
                obj.close();
                trace(">> "+obj.close);
            }catch (err:Error) 
            {
                trace(err)
            }
        }
        ItemsBuilder.thumbLoadersArray.splice(0, ItemsBuilder.thumbLoadersArray.length);
    }
}

Solution

  • Are you getting anything out of the trace?

    Flash has an internal limit with how many simultaneous loads it can do at once. You're loading 800 images in a loop, which means that the first ~780 or so will be overridden by the last 20 or so. The max I ever load at once is around 10 (I think BulkLoader has something similar). If you want to load in 800 images, use the array to keep track of what's loading in. Something like:

    private var m_imagesLoaded:int = 0;
    private var m_toLoad:Array = null;
    
    private function _init():void
    {
        // create your array and set the first 10 or so loading
        this.m_toLoad = new Array( 800 );
        ...
    }
    
    private function _onImageLoad( e:Event ):void
    {
        // load the next one in the list
        this.m_imagesLoaded++;
        this.m_toLoad[this.m_imagesLoaded].load();
    
        // do whatever else
    }
    

    As for close(), it "Cancels a load() method operation that is currently in progress for the Loader instance." If there's no load() going on in the Loader, then nothing's probably going to happen.

    P.S.: in your try statement, you're creating a new Loader everytime, before assigning it to something else. Just change it to

    var obj:Loader = ItemsBuilder.thumbLoadersArray[i];