-
removing event listeners
I'm loading and reloading sets of thumbs - load xml, generate thumb clips, load images into the clips, then removing the clips after user done interacting. Below is code to load the images.
I should remove the listener as each thumb is loaded, correct?
I looked around for code to remove the load listeners and came up with code below.
Is it correct? Is there a better way?
Code:
function loadScrubPic():void {
var picRequest:URLRequest = new URLRequest(thumbsXml.thumb[thumbLoadNo].thumbURL[0]);
var picLoader:Loader = new Loader();
picLoader.load(picRequest);
scrubThumbHoldersArray[thumbLoadNo].holder.addChild(picLoader);
picLoader.contentLoaderInfo.addEventListener(Event.INIT, scrubPicLoaded);
scrubThumbLoadersArray.push(picLoader);
}
function scrubPicLoaded(event:Event):void {
var thumbClip:DisplayObject = DisplayObject(LoaderInfo(event.target).content).parent.parent.parent;
// remove init listener
event.target.removeEventListener(Event.INIT, scrubPicLoaded);
thumbLoadNo++;
if (thumbLoadNo < thumbsXml.thumb.length()) {
loadScrubPic();
} else {
trace("\nall scrub thumbs loaded - " + scrubThumbHoldersArray.length);
}
}
Thanks for your help!
Last edited by schlag; 08-26-2010 at 12:33 PM.
-
Flash/Flex Developer
Essentially, you are correct. There are always a number of different way to perform a task, it is just all about the programmer. If the code is working and the listener is being removed, I suggest just keeping what you got.
Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.
-
Essentially doesn't sound good. How should I do it?
-
Code you posted is fine. It can't be any simpler than that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|