AS3: Notes on arguments… →← Apollo apps

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.

May 16th, 2007  by Stephen  /  8 Comments

Comments on “AS3: addFrameScript and BigMovieClip”

  1. Cool!

    But why call the init function “LabelEventMovieClip”? Shouldn’t that just be the constructor? Or is that just a typo?

    Eric on May 17th, 2007 at 12:23 pm
  2. 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. :)

    Nate Chatellier on May 17th, 2007 at 1:06 pm
  3. Eric, it was a typo. I’ve updated the class.

    Jamie on May 17th, 2007 at 1:54 pm
  4. Is this class has the side effect, if i have some script exist on the “labed frame”, it will be remove by “addFrameScript()”.

    dnaiel yuen on May 18th, 2007 at 1:29 am
  5. thats really cool… i have an as2 movieclip button api that could make good use of this kind of concept.. interesting post…

    ryan on June 14th, 2007 at 5:52 pm
  6. […] 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. […]

    TroyWorks » Blog Archive » Sketch: View Controller separation, MovieClip.addFrameScript on August 29th, 2007 at 12:21 am
  7. […] [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 » AS3: MovieClip.addFrameScript on September 22nd, 2007 at 10:24 pm
  8. […] [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 on December 20th, 2007 at 5:37 am