Articles

FramescriptManager: insert code on your timeline at runtime

In an earlier post we showed you how to seperate design and code by keeping code off the timeline at all times. The method was to have designers add framelabels to the movieclips’ timeline and have the developers react to the flash playhead reaching this framelable by means of an Event. This created a clean seperation between the job of coders and the job of designers.

We used the TimelineListener class as an example in that earlier post. This post will show you how to take an alternative approach, without event listeners, but by means of injecting code in a frame at runtime by means of our FrameScriptManager and the MovieClip.addFramescript method.

import nl.dpdk.utils.timeline.FramescriptManager;
//create the framescriptManager with a reference to the movieclip we want to add logic to
//we have a reference to the movieclip by name of "aMovieClip"
var f: FramescriptManager = new FramescriptManager(aMovieClip);
//register a callback for a specific label on the timeline of aMovieClip
f.add("showDone", onReady);
//and for another label
f.add("hideDone", onDone);
//start playing the timeline of aMovieClip, in this case it will begin playing 
//at the "show" framelabel which will eventually end at the "showDone" label
aMovieClip.gotoAndPlay("show");
 
//... somewhere else in our class, we have defined our methods that will be executed
/**
callback method called from the timeline of aMovieClip
this code will be executed when a specific framelabel has been reached
in this case, it signals that aMovieClip has executed it's intro animation
*/
private function onReady():void{
 //do something here, maybe dispatch an event, maybe start another chain of logic
}
 
/**
callback
*/
private function onDone():void{
 //do something here that is appropiate for when aMovieClip has done it's hiding thing.
}

that’s about it. It doesn’t get any easier than this :)
If you would like to read about the why’s of a thing like this, read our earlier post.

You can also find the alternative way there. Whichever method you choose is up to you, the can both achieve the same thing, but this method is really the fastest and shortest!

0 Responses to “FramescriptManager: insert code on your timeline at runtime”


  1. No Comments

Leave a Reply