Tôi có một mảng các đối tượng FileReference có nhiều trình nghe đính kèm với mỗi đối tượng, tôi có nên loại bỏ từng trình nghe trong phương thức xử lý của nó hay tôi nên xóa tất cả chúng trong trình xử lý hoàn chỉnh?Flex/AS3: Khi nào cần xóa người nghe?
Tôi đọc ở đâu đó để sử dụng tài liệu tham khảo yếu cho người nghe, nhưng tôi nghĩ rằng nó sẽ được tốt hơn để loại bỏ một cách rõ ràng người nghe (có?/Không?)
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);
}
Bài đăng trên blog của bạn cũng hữu ích, cũng đã kiểm tra MAX talk, cảm ơn. – Ronn