views:

138

answers:

1

Hi. I'm trying to make some flash buttons with a mouse_over animation that plays in reverse on mouse_out. Now I have it working for one of my three movie clip instances.

I am using e.currentTarget.play() instead of having a function for each movie clip, but how do I do the same for my playReverse function? I tried putting e.currentTarget.prevFrame() instead of mc1.prevFrame() but it did not work. My code is as follows:

mc1.addEventListener(MouseEvent.MOUSE_OVER,mover);
mc2.addEventListener(MouseEvent.MOUSE_OVER,mover);
mc3.addEventListener(MouseEvent.MOUSE_OVER,mover);
mc1.addEventListener(MouseEvent.MOUSE_OUT,mout);
mc2.addEventListener(MouseEvent.MOUSE_OUT,mout);
mc3.addEventListener(MouseEvent.MOUSE_OUT,mout);

function mover(e:MouseEvent):void {
    stopPlayReverse();
    e.currentTarget.play();
}

function mout(e:MouseEvent):void {
    this.addEventListener(Event.ENTER_FRAME, playReverse, false, 0, true);
}

function playReverse(e:Event):void {
    if (mc1.currentFrame == 1) {
        stopPlayReverse();
    } else {
        mc1.prevFrame();
    }
}

function stopPlayReverse():void {
    if (this.hasEventListener(Event.ENTER_FRAME)) {
        this.removeEventListener(Event.ENTER_FRAME, playReverse);
    }
}

Any idea how I can fix this?

+1  A: 

Your function playReverse only use mc1 how can it work with the others movie clip.

If you choose to do it that way you can keep a track of the current MovieClip playing in reverse. You will have to add more logic if you want that the play in reverse always finish when passing over one clip to another.

var currentMovieClip:MovieClip=null;

function mout(e:MouseEvent):void {
    var mc:MovieClip = e.currentTarget as MovieClip; 
    if (mc !== null) {
     currentMovieClip = mc;
     this.addEventListener(Event.ENTER_FRAME, playReverse, false, 0, true);
    }
}

function playReverse(e:Event):void {
    if (currentMovieClip==null) {
       return;
    }

    if (currentMovieClip.currentFrame == 1) {
        stopPlayReverse();
    } else {
        currentMovieClip.prevFrame();
    }
}

Another way that implies that you can have each clip to finish their play in reverse

function mover(e:MouseEvent):void {
    stopPlayReverse(e.currentTarget as MovieClip);
    e.currentTarget.play();
}

function mout(e:MouseEvent):void {
    var mc:MovieClip = e.currentTarget as MovieClip; 
    if (mc !== null) {
     mc.addEventListener(Event.ENTER_FRAME, playReverse, false, 0, true);
    }
}

function playReverse(e:Event):void {
    var mc:MovieClip = e.currentTarget as MovieClip; 

    if (mc.currentFrame == 1) {
        stopPlayReverse(mc);
    } else {
        mc.prevFrame();
    }
}

function stopPlayReverse(mc:MovieClip):void {
  if ((mc!==null) && mc.hasEventListener(Event.ENTER_FRAME)) {
    mc.removeEventListener(Event.ENTER_FRAME, playReverse);
  }
}
Patrick
That's fantastic thank you very much!
Probocop