Given that the new motion tween creates a bezier path, I’m guessing that we’ll have access to creating such a path with JSFL. Which led me to think about creating that path in real-time, similar to the real-time drawing that I’d seen from ScribbleBot on Chris’s blog. Instead of scribbling a line in real-time, I’d be sketching a motion path. There would be a variable to determine “smoothness” so that it doesn’t create an unmananageable amount of new motion keyframes. And it could probably be done with a custom tool rather than a panel, so that the sketching could be done directly on the stage.
That also leads me to wonder if there’s a way to record the armature animation in real-time and convert it to a motion tween, similar to the feature that already exists in After Effects CS3.
I know, I’m a nerd. The first idea there became MotionSketch. I haven’t yet found a way to accomplish the second idea with the armature, but I have a few ideas.
While at Flash Camp, I spoke with Richard Galvan and he directed me to John Mayhew, the engineer behind the new motion model in Flash. John was very affable and willing to follow up with me, but he didn’t know of any undocumented features offhand. Unfortunately, adding features to the JSFL API is usually somewhat of an afterthought because so much of the development time is spent on the new features themselves. I had a few ideas to use the new 3D features while at Flash Camp as well, but they were similarly left out of the JSFL API.
Flash seemed to be able to discern which type of motion it was copying or pasting and acting accordingly. So it occurred to me that I could grab the data from the motion clipboard and alter it before pasting it back. Additionally, if I wanted data from an existing tween, I could run a Copy Motion command, available to JSFL as of Flash CS3 thanks to Robert Penner’s Copy Motion feature, then go about altering and pasting. These are the extensions that I’ve created thus far using that very technique:
Below is a rundown of the steps I used in the extensions mentioned above. This technique can be used in lieu of the non-existent timeline.createMotionObjectTween() command. I refer to this as a “hack” because it’s an unsupported method, but given the complexity of what can be created with this new motion model, editing the XML is actually a fairly efficient way to go about creating/editing a tween. If the XML is not properly formed, it can cause Flash to crash when you try to paste the motion, or it can create some funky bugs in the Motion Editor. Be sure to test your code thoroughly before releasing anything for public consumption. The language is JSFL (used to automate and manipulate the Flash authoring environment). There’s a link to documentation for the AnimationCore XML listed in step 3.
Step 1: Store the motion clipboard so you can restore it when you’re done. In some cases, I store it as a file. In this example, I store it as a variable.
var tl = fl.getDocumentDOM().getTimeline();
var storedMotion = FLfile.read(MOTION_CLIPBOARD);
Step 2(a): Copy motion to clipboard, retrieve the new clipboard contents and convert to XML. Use this step if you want alter an existing motion tween. The MotionBlur extension uses this step.
var xmlstr = FLfile.read(MOTION_CLIPBOARD);
var motionXML = new XML(xmlstr)
Step 2(b): Instead of copying the motion, you can create a new tween by loading a more or less blank motion XML template and adding content to it. The MotionSketch extension uses this step.
Step 3: The motion XML can then be altered using E4X. This portion of the code is different for each extension, depending on what the extension is trying to accomplish. Here’s the documentation on CS4 Motion XML that Flash engineer John Mayhew graciously put together.
Step 4: Write the altered XML to the motion clipboard.
Step 5: Paste the altered motion.
Step 6: Restore the motion clipboard for the user.
If you want to know if a motion tween has already been applied, you can retrieve the tweenType property from the current frame. A classic tween will return a value of “motion” and a new motion tween will return a value of “motion object“. If you use Step 2(a), you’ll want to check and make sure you have a “motion object” selected before proceeding.
And there you have it.
There are other ways to go about this process. You could, since motion presets are just motion XML files, run this process through the Motion Presets panel’s JSFL calls, but this would require more steps than the process laid out above.
Update (1/12/10): Flash CS5 now has direct JSFL access to the calls documented in this post. Check out this video tutorial that I produced on ActiveTuts for more info.