Related Posts Plugin for WordPress, Blogger...
This form does not yet contain any fields.

    Our products are on iTunes!

     Nanaimo Studio

    Find us on Google+ 


    We are listed on: Dmegs Link Directory

    Blog Index
    404 page
    « Renaming Project in Xcode the Simple Way | Main | Minor fix to Gaia Flash Framework »

    How to make function calls without injecting any code into your FLA?

    When you are working with FLA, there are times when you need to perform a specific action when you reach a certain frame in your movieclip.  The common practice is to either insert the actual chunk of code into the actual keyframe.  The big issue with this approach is that now you have just created some timeline code, which can be a pain to track down since the majority of your code lies in external actionscript files.  For coders who are vigilant in staying away from too much timeline code, they might resort to putting a line of code in that frame to either dispatch an event or call a method in a class associated with the movieclip in the key frame.  The problem with this is that timeline code is still being created, even though it's much less and the actual function can now lie in the external actionscript file.

    Fortunately, AS3.0 introduces a very useful but seldom used FrameLabel class (flash.display.FrameLabel).  With this class, you are able to obtain all the frame labels along with its associated frame number on your movieclip's main timeline via MovieClip's currentLabels property, which returns an array of FrameLabel objects.

    Now that you can get the labels on the timeline , the next thing you need to do in order to know if you have reached the frame is to listen to ENTER_FRAME event and check to see what frame label you are currently on (via MovieClip's currentLabel property).  When the playhead reaches the actual frame label, make it call the method you want.

    There is still one redundancy -- for every frame label, you need to specify the handler to call when it's reached.  Wouldn't it better if you can just specify the method handler's name as the label name such that when the frame label is reached, a method handler with the same name will be called?  Not only will this result in less code, the frame label is now self-documenting -- just by reading the frame label you know which method will be called when the frame is reached.

    I have create a class called FrameLabelAction that does precisely this.  You can download it here.

    Basic Usage:

    import com.nanaimostudio.utils.FrameLabelAction;

    public class YourMovieClip extends MovieClip

       var actionContainer;

       public function YourMovieClip()

           // automatically associates methods with the same name as frame labels
           // and trigger it when the frame label is reached.
           actionContainer = new FrameLabelAction();

           // start frame label detection


       // Assuming you have a frame label in your MovieClip called transitionInComplete,
       // this method will be called when the playhead reaches this frame label.
       public function transitionInComplete():void

            // stop frame label detection - optional as the detection
            // will be stopped when the last frame label is reached
            // and method triggered.


    PrintView Printer Friendly Version

    EmailEmail Article to Friend

    Reader Comments

    There are no comments for this journal entry. To create a new comment, use the form below.

    PostPost a New Comment

    Enter your information below to add a new comment.

    My response is on my own website »
    Author Email (optional):
    Author URL (optional):
    Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>