2011-06-15 66 views
1

這是我在一個連續加載圖像的圖庫中使用的代碼。當您必須打開不同的影像專輯並且必須消除動畫片段中以前加載的所有孩子時,我的問題纔會出現。當我加載新相冊時,我使用了您在此發佈的代碼:AS3 How to remove previous loaders,但問題在於,有時用戶在所有圖片出現之前都會離開相冊頁面,因此當他們點擊新相冊打開相冊時,新圖片會被放置在其他位置導致裝載機已經啓動。我試圖關閉()加載程序,但它似乎不工作。如果你能幫我一把,我會感激不盡。先謝謝了。在這裏,您可以看到工作現場www.barbarabritvin.com(看什麼IM交談abouy你必須點擊專輯,之前所有圖片加載離開,並開闢一個又一個。來自阿根廷加油!由於無法關閉()加載程序,因此無法刪除庫中的所有加載的子項!

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) 
} 



} 
+1

**請**看看這個鏈接:http://www.adobe.com/devnet/actionscript/articles/oop_as3.html – Marty 2011-06-15 02:51:55

回答

1

我會強烈建議LoaderMax通過使用GreenSock。

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

我使用它的一些非常重大的加載/卸載,並處理了很多清理工作。

+0

我會給它一看!非常感謝你! – nlalli87 2011-06-15 07:22:10

1

一種方式去了解它會分配一個容器到每個專輯。通過這種方式,當你想加載一個新的相冊時,你只​​需擺脫先前的容器並將新的容器添加到顯示列表。

如果你使用OOP方法(參見Marty Wallace的鏈接),一個可能的解決方案可能是創建一個Album類,它可以處理其內容的加載(可能通過LoaderMax)。選擇一個新的相冊,將從顯示列表中刪除前一個,並存儲它以供以後調用。

LoaderMax是相當有用的,你應該檢查出來。您可以創建加載順序並根據用戶的交互情況隨意修改它。

+0

我嘗試了第一個aproach,但遇到了一些問題,所以繼續與我有什麼;這是這個。但我可能不得不回去嘗試LoaderMax方法後的方法!謝謝! – nlalli87 2011-06-15 07:24:01

0

如果使用OOP,您可以用三個核心要素構建應用程序:

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

Main將控制加載Album,這將排隊並加載實例Photo。當Album關閉時,可以刪除包含的Photo實例,並且可以忽略當前排隊的Photo(s)。我有。