Game Development Reference
In-Depth Information
private function dispatchFrameEvent():void {
dispatchEvent(new Event(currentLabel));
The enumerateFrameLabels method iterates through the list of
FrameLabel objects in the Array currentLabels and adds a frame
script to every frame that has a label. The function it adds is called
dispatchFrameEvent , and all it does is to generate a new event with
the same name as the frame label. Now, every time a frame label
is hit, an event with that label name will be dispatched. By using
events, any number of objects can listen for these frame events.
The rewritten constructor for this class now looks something more
like the following:
public function FrameScriptExample() {
addEventListener(FRAME_TITLE, setupTitle, false, 0, true);
protected function setupTitle(e:Event):void {
It is worth noting that only one function can be assigned to
aframeatatime,soanysubsequent addFrameScript calls to the
same frame number will replace the existing script. If you
re at all
nervous about using undocumented features in your work, add-
FrameScript is a pretty safe bet
s what the CS5 IDE uses intern-
ally when you place code on the timeline. Let
s say you put a script
on the last frame of the main timeline called stop() .Whenyou
compile the SWF, Flash takes each of these frame scripts and con-
verts them into functions with names such as
to ensure
they are unique. Then, in the constructors for any clips with frame
scripts, Flash calls addFrameScript to attach these functions to their
respective frames. It looks something like the following:
addFrameScript(30, frame30);
m sure there are many other good applications of this method,
so continue to explore it and let
s collectively push Adobe to sup-
port and document it. If it
s good enough for Flash, it should be
good enough for you. One other minor sticking point is that very
early versions of Flash Player 9 prior to Flash CS3
s release (specifi-
cally, 9.0.28 and earlier) do not support addFrameScript .Thecom-
mand is ignored entirely. Because of this issue, other security
issues, bug fixes, and performance improvements, I recommend
you to only build for Flash Player 9.0.115 or higher. If you
re build-
ing for Flash Player 10 (which is the default for CS5), you don
need to worry about it at all.
Search Nedrilad ::

Custom Search