Skip navigation
Currently Being Moderated

removing event listeners on leaving a frame

Mar 15, 2012 10:08 PM

Hi team,

I am having a bit of trouble, I have l modded some code that I am really happy with, it makes buttons bounce around for the user to try to click on when entering a certain frame...

Problem.. I notice tha the code adds eventlisteners ENTER_FRAME to make this work, when you leave that frame there are now problems with null objects becuase the listeners are still on but the objects are not there anymore..

 

Ok so attempted solution - I can use a currentLabel on the main timeline to check if the correct frame is reached then use a function if (label is x) put listeners on else take them off... works but then I have to have these objects hidden on the timeline  and then add visible=true/false to my framelabel listener.. This works but part of my functionality here is that these movieclips that move are buttons that the user clicks on and they explode and dissapear- but now they dont because I have a code that says on that frame they should be visible..

 

 

The only thing I can think of is to have a blank frame at the end of the explode and put a stop on it.  Then add a gotoAndPlay(1) into my frame label code.  Seems very ugly, you guys got a better way?  Can I remove eventlisteners on leaving a frame?  Is there a code like LEAVE_FRAME????

cheers

sub

 
Replies
  • kglad
    72,322 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 15, 2012 10:26 PM   in reply to subtlefly72

    use the removedfromstage event:

     

    amovieclipwithanenterframeevent.addEventListener(Event.REMOVED_FROM_ST AGE,removedF);

     

    function removedF(e:Event):void{

    e.currentTarget.removeEventListener(Event.ENTER_FRAME);

    e.currentTarget.removeEventListener(Event.REMOVED_FROM_STAGE);

    }

     
    |
    Mark as:
  • kglad
    72,322 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 15, 2012 10:54 PM   in reply to subtlefly72

    yes, it goes in the keyframe where those movieclips exist.  if the movieclips exist on a main timeline frame, that's where that code should be placed.

     

    that code should execute when the movieclip exists.  the listeners wait for the movieclips to be removed from the display list.  that happens when you navigate away from the frame that contains those movieclips.

     
    |
    Mark as:
  • kglad
    72,322 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 16, 2012 6:05 AM   in reply to subtlefly72

    use the trace() function to find why it is not working.  start by making sure your movieclip is being removed from the stage.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points