开发者

Can't remove all loaded children in a gallery because can't close() a loader!

This is the code i used in a gallery that loads images sequentally. My problems comes in when you have to open a different image album and have to eliminate all the previously loaded children in the movieclip. When i load a new album i used a code you posted here: AS3 How to remove previous loaders but the problem is that sometimes the user leaves the album page before ALL the pics laod so when they click on a new album to open it a new image is placed somewhere else cause the loader 开发者_运维知识库has already been launched. I've tryd to close() the loader but it doesn't seem to work. I'd appreciate it inmensly if you can give me a hand. Thanks in advanced. Here you can see the working site www.barbarabritvin.com (to see what im talking abouy you have to click on an album, leave before all the pictures load and open up another one. Cheer from Argentina!

getImage(dataList[0].file)


function getImage(href:String):void {


var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageReady);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
loader.x=xCounter
loader.load(new URLRequest(href));

} 


function imageReady(e:Event):void {
var bitmap:Bitmap=e.target.content;
if (bitmap!=null) {
    bitmap.smoothing=true;
}

displayLarge2.thumb_loader.thumbHolderInside.addChildAt(e.target.loader,0)
yaCargo=true


trace("NUMCHILDREN"+displayLarge2.thumb_loader.thumbHolderInside.numChildren)


collection.push(e.target.content);
xCounter=xCounter+e.target.loader.width+3
imagecounter++;
if(imagecounter < dataList.length() && loadingPics==true) {
getImage(dataList[imagecounter].file);
}

}

function clearThumbs():void
    {
        while(displayLarge2.thumb_loader.thumbHolderInside.numChildren > 0)
        {
            //Remove the first child until there are none.
            displayLarge2.thumb_loader.thumbHolderInside.removeChildAt(0);
        }
    }


displayLarge2.close.addEventListener(MouseEvent.CLICK, closeAlbum)




function closeAlbum(e:MouseEvent):void{
displayLarge2.thumb_loader.thumbHolderInside.enabled=false
loadingPics=false


            while(displayLarge2.thumb_loader.thumbHolderInside.numChildren>0) 
    { 
          displayLarge2.thumb_loader.thumbHolderInside.removeChildAt(0)
    } 


        trace("NUMCHILDREN"+displayLarge2.thumb_loader.thumbHolderInside.numChildren)

imagecounter=0
xCounter=0

displayLarge2.enabled=false
displayLarge2.mouseChildren=false






var scrollerTween=TweenManager.create(displayLarge2,"alpha",Regular.easeIn,1,0,0.5,true);
scrollerTween.addEventListener(TweenEvent.MOTION_FINISH, doNextTween)
function doNextTween(e:TweenEvent):void{


    sectionThumbs.enabled=true
    sectionThumbs.mouseChildren=true
    displayLarge2.visible=false

    var          thumbsTween=TweenManager.create(sectionThumbs,"alpha",Regular.easeIn,0,1,0.5,true);
    scrollerTween.removeEventListener(TweenEvent.MOTION_FINISH, doNextTween)
}



}


I would highly recommend LoaderMax by greensock.

http://www.greensock.com/loadermax/

I use it for some pretty major loading/unloading and handles alot of the cleanup.


One way to go about it would be to assign a container to each album. In this way, when you want to load a new album , you simply get rid of the previous container and add the new one to the display list.

If you use an OOP approach ( see Marty Wallace's link ) , one potential solution could be to create an Album class , that could handle the loading of its content ( possibly via LoaderMax ). Selecting a new album, would remove the previous one from the display list , and store it for later recall.

LoaderMax is quite useful, you should check it out. You can create a loading sequence and modify it at will, dependent on your user interaction.


If you use OOP, you can structure your application with three core elements:

  1. Main -> MovieClip
  2. Album -> MovieClip
  3. Photo -> Loader

Main will control loading an Album, which will queue and load instances of Photo. When an Album is closed, contained instances of Photo can be removed, and the currently queued Photo(s) can be ignored.

I have got you started here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜