May 16, 2007

AS3: addFrameScript and BigMovieClip

Coming off the heels of this blog post about dynamically attaching code to frames in AS3, I decided to foray into ending the use of timeline code altogether.

I failed.

But I did come up with a handy dandy script that will certainly come closer.

Click on for the script and documentation.


AS3 BigMovieClip
AS3 FrameEvent

What It Does
On construction, it combs through the list of all frame labels on the timeline and indexes them in an object. From there, you can assign methods to specific frame labels by virtue of:


addMethodToLabel($label:String,$evt:Function):void
Example: myClip.addMethodToLabel("MY_LABEL",_onMyLabelIn); // function _onMyLabelIn fired when we hit frame label "MY_LABEL"


To remove?
removeMethodFromLabel($label:String):void

In addition, EVERY frame label dispatches a FrameEvent, allowing you the option to listen and act on frame labels from wherever you want. Each FrameEvent object contains a FrameLabel (flash.display.FrameLabel), so you know which clip, frame and label has been reached.

Share this Post


                           

Comments


Joel     Sep 22, 2008
Hi!

It seens that the links to the scripts are broken!! Too bad since this idea is certainly interesting!

TroyWorks » Blog Archive » AS3: MovieClip.addFrameScript     Dec 20, 2007
[...] [1] Senoculars post [2] FlashGurus info as Senocular [3] BIG SPACESHIP, Extending addFrameScript to use the frame labels instead of framenumbers... the same glue I'm using as well, though I'm more interested in events being generated, than script. [...]

TroyWorks » Blog Archive » AS3: MovieClip.addFrameScript     Sep 22, 2007
[...] [3] BIG SPACESHIP, Extending addFrameScript to use the frame labels instead of framenumbers… the same glue I’m using as well, though I’m more interested in events being generated, than script t [...]

TroyWorks » Blog Archive » Sketch: View Controller separation, MovieClip.addFrameScript     Aug 29, 2007
[...] BigSpaceShip Has an interesting take of introspecting the movieClip labels and attaching a script. This fits into the Sketch philosophy of using minimal or no code in the view to indicate state. http://labs.bigspaceship.com/blog/?p=43 Though Sketch differs, while it too introspects the framelables, it treats this as an event to broadcast so more than one party can listen, addFrameScript is like removing that intermediate event and directly calling a script instead, though this will override any script insde inside the timeline, so in some ways polling based on EnterFrame events is less prone to breaking something the designer is doing. [...]

ryan     Jun 14, 2007
thats really cool... i have an as2 movieclip button api that could make good use of this kind of concept.. interesting post...

dnaiel yuen     May 18, 2007
Is this class has the side effect, if i have some script exist on the "labed frame", it will be remove by "addFrameScript()".

Jamie     May 17, 2007
Eric, it was a typo. I've updated the class.

Nate Chatellier     May 17, 2007
Note that you can also use Tweener (http://code.google.com/p/tweener/) to execute a timeline animation without using the .play() method, and Tweener has built in support for onStart, onUpdate, and onComplete functions. This is how fire off all my code when a timeline animation completes and it works great. :)

Eric     May 17, 2007
Cool!

But why call the init function "LabelEventMovieClip"? Shouldn't that just be the constructor? Or is that just a typo?


Speak






Submit »