Previously I blogged about using the new Copy Motion to ActionScript 3 feature. Now I I would like to show you how to take that feature and extend it to Flex.
I have included my FFanimaotr flex project that has a working sample of this. You must have Flex and Flash CS3 installed for this to work since we need the Animator class that ships with Flash CS3. Just import the project to Flex and it should work.
Here is the Flex code:
|
<?xml version="1.0" encoding="utf-8"?> <mx:HTTPService url="{ combo.selectedItem + ‘.xml’ }" resultFormat="e4x" id="xmlService"/> <mx:Script>
<
Ok, so how does this work? simple, you just run the same AS3 code that I showed before (in Red). Except this time you tell it to animate a Flex component. In this case I am using the calendar component, but feel free to replace it with any component (SWFloader, VideoDisplay, etc) just make sure to give it an ID of "moveThis".
The only thing I am doing a bit different than what I did in my Flash CS3 example is calling Animator’s rewind function. as in:
if (my_animator) my_animator.rewind();
I am doing this so that when you select a different animation the component you are animating doesn’t continue from where it finished and fly off the page.
My example is actually more complicated than it needs to be. I am using a combo box with two animations you can select from. When one is selected it calls my animate function with in tern loads the XML file and then uses the Animator class to apply the animation to any component that has an ID of "moveThis". The beauty is that its all at runtime.
Play around with it. See what you can do with it and if you think you have something cool please share.



