Hi guys, ok I have movieclips which have timeline animations on them as they are animated buttons. So, I want to set up the following listeners…
MOUSE_OVER -> Play the movieclip and delete the enterframe when it hits the last frame
MOUSE_OUT -> Rewind the movieclip
CLICK -> Delete the listener so basically the button is “selected” and the MOUSE_OUT won’t happen when the user takes their mouse off the button.
Now it’s the CLICK handler I’m having trouble with. I’m not sure if I quite understand removing listeners yet! Anyways, here’s my code. The current status is that the MOUSE_OUT action still happens even after the button has been clicked…
package com {
import flash.events.Event;
import flash.events.MouseEvent;
public class MovieClipButton {
public function MovieClipButton(target) {
target.addEventListener(MouseEvent.MOUSE_OVER, eventHandler);
target.addEventListener(MouseEvent.MOUSE_OUT, eventHandler);
target.addEventListener(MouseEvent.CLICK, eventHandler);
}
public function eventHandler(e:MouseEvent) {
switch (e.type) {
case "mouseOver" :
trace("OVER");
e.target.addEventListener(Event.ENTER_FRAME, doPlay);
break;
case "mouseOut" :
trace("OUT");
e.target.addEventListener(Event.ENTER_FRAME, doRewind);
break;
case "click" :
trace("CLICK");
e.target.removeEventListener(MouseEvent.CLICK, eventHandler);
break;
}
}
public function doPlay(e:Event) {
e.target.gotoAndStop(e.target.currentFrame+1);
if (e.target.currentFrame == e.target.totalFrames) {
e.target.removeEventListener(Event.ENTER_FRAME, doPlay);
}
}
public function doRewind(e:Event) {
e.target.removeEventListener(Event.ENTER_FRAME, doPlay);
e.target.gotoAndStop(e.target.currentFrame-1);
if (e.target.currentFrame == 1) {
e.target.removeEventListener(Event.ENTER_FRAME, doRewind);
}
}
}
}
I really hope someone can help. Thanks guys!
PS: One other thing… is there a way to trace out all the listeners (and maybe some data about them, type etc) currently on an object?