Sunday, March 14, 2010
Simple application using Timer in Action Script 3
package
{
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class TimerClass extends Sprite
{
var _square:Sprite;
var _circle:Sprite;
public function TimerClass()
{
_square = new Sprite();
_circle = new Sprite();
_square.graphics.beginFill(0x660033);
_square.graphics.drawRect(0,0,100,100);
_square.graphics.endFill();
_circle.graphics.beginFill(0x660033);
_circle.graphics.drawCircle(50,50,50);
_circle.graphics.endFill();
addChild(_square);
addChild(_circle);
_circle.x = 200; // xy postion
_circle.y = 200;
_square.x = 100; // xy postion
_square.y = 50;
var sqTimer: Timer = new Timer(50,0);
sqTimer.addEventListener(TimerEvent.TIMER,SquareTimer);
sqTimer.start();
var cTimer:Timer = new Timer (50,0);
cTimer.addEventListener(TimerEvent.TIMER,CircleTimer);
cTimer.start();
}
public function SquareTimer(event:TimerEvent):void
{
if (_square.x <=150)
_square.x++;
}
public function CircleTimer(event:TimerEvent):void
{
if (_circle.x >=150)
_circle.x--;
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment