<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" xmlns:utils="utils.*"
viewSourceURL="srcview/index.html"
width="300" height="50">
<fx:Script>
<![CDATA[
import spark.effects.animation.Animation;
import spark.effects.animation.RepeatBehavior;
import utils.AnimationEvent;
private var anim:Animation;
private function updateHandler(event:AnimationEvent):void
{
button.x = event.animation.currentValue["x"];
}
private function startAnimation():void
{
anim = new Animation(500, "x", 0, width - button.width);
anim.repeatBehavior = RepeatBehavior.REVERSE;
anim.repeatCount = 0;
anim.animationTarget = animTarget;
anim.play();
}
]]>
</fx:Script>
<fx:Declarations>
<utils:AnimationTargetDispatcher id="animTarget"
update="updateHandler(event)"/>
</fx:Declarations>
<s:Button id="button" label="Move Me" click="startAnimation()"/>
</s:Application>