Quick Animator example

My first little contribution to a brand new forum…

While the Animator class is mainly used for the Copy as Motion to AS3 command, you can of course hand code it as well. Here’s a quick color change example I whipped up the other day while playing around…

[AS]import fl.motion.Animator;
import fl.motion.MotionEvent;

var redSprite:Sprite = new Sprite();
redSprite.graphics.beginFill(0xFF0000);
redSprite.graphics.drawRect(50, 50, 100,100);
redSprite.graphics.endFill();
addChild(redSprite);

var blue_xml:XML = <Motion duration=“10” xmlns=“fl.motion." xmlns:geom="flash.geom.” xmlns:filters=“flash.filters.*”>
<source>
<Source frameRate=“31”></Source>
</source>

&lt;Keyframe index="0"&gt; 
    &lt;tweens&gt; 
        &lt;SimpleEase ease=".8"/&gt; 
    &lt;/tweens&gt; 
&lt;/Keyframe&gt; 

&lt;Keyframe index="20"&gt; 
  &lt;color&gt; 
     &lt;Color blueOffset="255" redOffset="-200"/&gt; 
  &lt;/color&gt; 

</Keyframe>
</Motion>;

var red_xml:XML = <Motion duration=“10” xmlns=“fl.motion." xmlns:geom="flash.geom.” xmlns:filters=“flash.filters.*”>
<source>
<Source frameRate=“31” />
</source>
<Keyframe index=“0”>
<tweens>
<SimpleEase ease=".8"/>
</tweens>
<color>
<Color blueOffset=“255” redOffset="-200" />
</color>
</Keyframe>

&lt;Keyframe index="20"&gt; 
  &lt;color&gt; 
     &lt;Color blueOffset="0" redOffset="0" /&gt; 
  &lt;/color&gt; 

</Keyframe>
</Motion>;

var color_animator:Animator;

redSprite.addEventListener(MouseEvent.ROLL_OVER, changeToBlue);
redSprite.addEventListener(MouseEvent.ROLL_OUT, changeToRed);

function changeToBlue(e:MouseEvent):void {
color_animator = new Animator(blue_xml, e.target as Sprite);
color_animator.play();
}
function changeToRed(e:MouseEvent):void {
color_animator = new Animator(red_xml, e.target as Sprite);
color_animator.play();
}[/AS]

I’m sure other folks will do much cooler stuff, but it’s a start…