# Quick Animator example

**URL:** <https://forum.kirupa.com/t/quick-animator-example/223822>\
**Category:** flash\
**Created:** [April 26, 2007, 1:27am UTC](https://forum.kirupa.com/t/quick-animator-example/223822 "2007-04-26T01:27:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![devonair](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@devonair](https://forum.kirupa.com/u/devonair)\
**Post date:** [April 26, 2007, 1:27am UTC](https://forum.kirupa.com/t/quick-animator-example/223822/1 "2007-04-26T01:27:08Z")

</div>

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…
