我有一個FileReference對象的數組,每個都有幾個偵聽器,我應該刪除它的處理程序方法中的每個偵聽器,還是應該在完整處理程序中刪除它們?Flex/AS3:何時刪除監聽者?
我讀的地方使用了聽衆弱引用,但我認爲這將是最好明確刪除監聽器(是嗎?/否?)
for each(var f:Object in fileCollection){
var myFile:FileReference = f.file;
myFile.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onUploadCompleteData)
myFile.addEventListener(ProgressEvent.PROGRESS, onProgress);
myFile.addEventListener(IOErrorEvent.IO_ERROR, onError);
myFile.addEventListener(Event.COMPLETE, onComplete);
}
private function onUploadCompleteData(e:DataEvent):void{
// doin my thing here
removeListeners(e)
}
private function removeListeners(e:Event):void{
var myFile:FileReference = FileReference(e.target)
myFile.removeEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onUploadCompleteData)
myFile.removeEventListener(ProgressEvent.PROGRESS, onProgress);
myFile.removeEventListener(IOErrorEvent.IO_ERROR, onError);
myFile.removeEventListener(Event.COMPLETE, onComplete);
}
您的博客文章是有幫助的,也檢查了最大的談話,謝謝。 – Ronn 2009-01-25 03:22:48