Capture me if you can
Copy Motion as Animation (or shall we call it "Motion Capture?") opens a whole new world to the coders. What used to be the realm of motion graphics artists is now opened to the left brainer as well. While some will argue that what's visual should remain visual (i.e. done in timeline so it can be tweaked there more easily), there are times when doing it in code is very beneficial, for example, by virtue of using a variable in the E4X that describes the animation, you can create dynamically varied animation based on a given motion spec. Another benefit is the ability to version control it and maintain a library of these effects over time. It's also very easy to create an AIR app to read in all the motion code, render them and change the various parameters in runtime.
When you do Copy Motion as Animation, you get back two main things:
1) E4X describing your motion
2) An fl.motion.Animator instance that will perform the motion based on (1) on a specified instance name.
Notice the things that can be changed here: the motion parameters in the E4X, and the variable that the motion operates on. Essentially, you can wrap this code inside a for loop and use it to animate all your instances on stage with varied parameters so they look random.
One thing to watch out for if you do decide to put the code in your class is to not paste the motion code as is into a method in your class. Following are some suggestions/tips for you:
1) (Optional) Use addFrameScript call to insert the actionscript code that will in turn call your motion code.
addFrameScript(0, animate);
Or you can call your animation at an appropriate time if you don't want to play the moment the movieclip exists on timeline.
2) (Required) Make the Animator instance a class member instead of local variable. If you copy and paste the generated code as is, the animator instance will be a local variable in your method. You might find out that the animation never runs. The reason is because once the method exits, the variable is out of scope, therefore the enterFrameBeacon for the animation will no longer fire.
3) (Optional) When you have the animation on the timeline, you can rely on the playhead to loop back but when you are doing it in code, you have to do a code loopback. So set repeatCount = 0 if you want your animation to loop.
4) (Optional) Use E4X's data binding syntax { } for your motion code to generate dynamic behavior.


Monday, November 3, 2008 at 3:38AM