Graphics Reference
In-Depth Information
everything and move on. The first of the last steps is to remove the
TimerEvent listener, so we can clear up a little memory. Next, we
ll
dispatch a DataEvent and pass our
REVERSE_COMPLETE
variable from
earlier as the type.
'
TIP
For dispatching a simple event where you just need to listen for a custom
name but you don
t need a full blown custom event class, consider
dispatching a DataEvent and using your custom event name as the type
parameter.
'
private static function replay():void {
if (_currentLoop
_loopCount) {
_currentLoop++;
_targetClip.play();
}else{
_revTimer.removeEventListener(TimerEvent.TIMER,reverseFrame
);
<
_targetClip.dispatchEvent(new
DataEvent(REVERSE_COMPLETE,true));
_targetClip = null;
}
}
Sample Use of ReverseClip
For this sample, place a MovieClip in your library and give it
a Class/Linkage of
“
ball
”
(or use the .fla available in the down-
loads from the topic
s Web site). After creating a new instance
of ball named
myBall
, we jump straight into the action by
adding a
REVERSE_COMPLETE
listener to the ReverseClipSample
itself. Next, we
'
regoingtousethewonderful
addFrameScript
to add a function to the final frame of
myBall
.Thatmethod,
rewindBall
, can have any code in it that you need, but let
'
sbe
sure to include the line that tells ReverseClip to play and target
myBall
for1loop(orasmanyasyou
'
'
d like). Now that we
'
re all
'
set up, let
saddtheballtothedisplaylistusing
addChild
.Lastly,
reverseCompleteHandler
simply traces out a notification that it
has indeed been called. Again, use the code that best suits your
project here.
package com.flashadbook.base {
import com.flashadbook.utils.ReverseClip;
import flash.display.Sprite;
import flash.events.DataEvent;
import flash.events.EventDispatcher;