<?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"
viewSourceURL="srcview/index.html"
width="300" height="50">
<fx:Script>
<![CDATA[
private var timer:Timer = new Timer(20, 0);
private var moveIncrement:Number = 10;
private function timerHandler(event:Event):void
{
button.x += moveIncrement;
if (button.x + button.width > width)
{
button.x = width - button.width;
moveIncrement = -moveIncrement;
}
else if (button.x < 0)
{
button.x = 0;
moveIncrement = -moveIncrement;
}
}
private function startAnimation():void
{
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
}
]]>
</fx:Script>
<s:Button id="button" label="Move Me" click="startAnimation()"/>
<s:HGroup y="40">
<s:Label text="Delay"/>
<s:HSlider id="slider" minimum="1" maximum="250" value="20"
change="timer.delay = slider.value"/>
</s:HGroup>
</s:Application>