Graphics Reference
In-Depth Information
public static function play(targetClip:MovieClip,
loopCount:int=0, targetFrame:int=1, speed:Number=30):void {
if(!_revTimer.hasEventListener(TimerEvent.TIMER)){
_targetClip = targetClip;
_targetFrame = targetFrame;
_loopCount = loopCount;
_revTimer.delay = speed;
_revTimer.addEventListener(TimerEvent.TIMER,
reverseFrame, false, 0, true);
}
_revTimer.start();
}
The
reverseFrame
method that gets called as a result of
_revTimer
firing off a TimerEvent makes a simple decision to either move the
MovieClip back by one frame or not. So, first it compares the
currentFrame
property of
_targetClip
to the value of
_targetFrame
.
If
_targetClip
hasn
'
'
t reached that point on the timeline yet, we
ll
tell it to go backwards by one frame (
prevFrame
). Remember, we
re
testing to see if
currentFrame
is greater than
_targetFrame
because
the MovieClip is playing backwards at this point. So if it
'
s
not greater, then we need to stop rewinding. The first thing to do in
this case is to force the MovieClip to
gotoAndStop(_targetFrame)
.
This step is really just a fallback to make sure the timeline didn
'
'
tgo
too far. Since we
re accounting for
the possibility that the playhead reversed too far by at least one
frame. Next, we
'
re forcing the frame number, we
'
ll
reset
the timer, so it will be ready to go when/if
we need it again. At the end of this piece, let
'
'
schecktoseeif
_loop
Count
is equal to
‒
1 (remember, that means infinite looping). If it is
equal to
1, all we need to do is tell
_targetClip
to
play
again. On
the other hand, if
_loopCount
is not equal to
‒
‒
1, we
'
ll call the
replay
method.
private static function reverseFrame(e:TimerEvent):void {
if(_targetClip.currentFrame
>
_targetFrame){
_targetClip.prevFrame();
}else{
_targetClip.gotoAndStop(_targetFrame);
_revTimer.reset();
_loopCount==
‒
1 ? _targetClip.play() : replay();
}
}
And now for the
replay
method. The replay method also
consists of a pretty simple if/else statement. Our test this time is to
see if
_currentLoop
is less than
_loopCount
. If it is, we increase
_currentLoop
and tell
_targetClip
to play again (or loop).
If
_currentLoop
is not less than
_loopCount
,it
'
s time to stop