dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: removing event listeners

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    27

    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.

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    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.

  3. #3
    Junior Member
    Join Date
    Jan 2008
    Posts
    27
    Essentially doesn't sound good. How should I do it?

  4. #4
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center