Understanding EventListeners in AS3? How to pause an EventListener?

Apari
Apari used Ask the Experts™
on
I am trying to work out a bit of AS3 to get it to trigger on a mouse or roll over. I've sort of worked out that bit, but what was happening was if the mouse didn't leave the area, it kept firing the same event.

I've tried adding a remove.EventListener but it stops the action altogether. Am I on the right track?

How do I stop the event after it happens until the mouse leaves the area and then trigger it again when it returns?

Any assistance would be appreciated.
function onImageEvent(event:SSPImageEvent) {
   if (event.type=="imageRollOver") {
       animate(true);
   }
	  
	  if (event.type=="imageRollOut") {
       animate(false);
	   // my_ssp.removeEventListener(SSPImageEvent.IMAGE_ROLLOVER, onImageEvent);
   }
}

function onThumbEvent(event:TGRequestEvent) {
   animate(false);
}

function animate( show:Boolean ):void {
   var end:int = show == true ? 1 : 0;
   _tween = new Tween( my_tg, "alpha", Strong.easeOut,  my_tg.alpha, end, .5, true );
   if( ! show ){
       _tween.addEventListener( TweenEvent.MOTION_FINISH, onComplete );
   } else {
       my_tg.y = 390;
       my_tg.alpha = 1;
   }
}

function onComplete(e:TweenEvent) {    
   my_tg.y = 615;
   my_tg.alpha = 0;
}

my_ssp.addEventListener(SSPImageEvent.IMAGE_ROLLOVER, onImageEvent);
my_ssp.addEventListener(SSPImageEvent.IMAGE_ROLLOUT, onImageEvent);
my_tg.addEventListener(TGRequestEvent.LOAD_THUMB, onThumbEvent);

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
im not sure what youre trying to do. But in general mouse event listeners are created as below:
//ROLLOVER EVENT
button_btn.addEventListener(MouseEvent.ROLL_OVER, overfunction);
function overfunction(e:MouseEvent):void{

// your function
}

//ROLLOUT EVENT
button_btn.addEventListener(MouseEvent.ROLL_OUT, outfunction);
function outfunction(e:MouseEvent):void{

// your function
}

//CLICK EVENT
button_btn.addEventListener(MouseEvent.CLICK, clickfunction);
function clickfunction(e:MouseEvent):void{

// your function
}

Author

Commented:
The API uses imageRollOver.

Please bear with me as I am a little confused. Is adding a remove.EventListener removing the listener altogether? Does that mean once it's executed the Event Listener is completely removed?

What does the void do in your example?
Top Expert 2009
Commented:
I'm not sure how slideshowpro works but the event listener model that you're currently using, the image rollover is triggering continuously right?

i think in your case removing the listener is not the best thing to do, as you need it again.
what i would probably do is create a variable to check if the animate has been triggered. then in the event listener check for that, so if its busy animating or has already animated, don't do anything, else do the animate.

Author

Commented:
Hi blue-genie,

Yes, you are right it is triggering continuously.

Logically, that is what I thought I would need but I'm not sure how to do it.

Commented:
if you are removing the event listener then you have to enable it also..

for eg.

onMouseOver - you remove the listener.
onMouseOut  -  you again add the listener.

That should work fine.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial