package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
[SWF(width="888", height="888")]
public class runRound extends Sprite
{
private var t:int=0; //起始
private var r:int=100; //运行圆圈半径
private var rd:Sprite=new Sprite(); //圆
public function runRound()
{
rd.graphics.beginFill(0x123123);
rd.graphics.drawCircle(100, 100, 30) //画圆
addChild(rd);
var start:TextField=new TextField;
start.text="开始";
start.x=10;
start.y=20;
start.addEventListener(MouseEvent.CLICK, startGo);
addChild(start);
var pause:TextField=new TextField;
pause.text="暂停";
pause.x=50;
pause.y=20;
pause.addEventListener(MouseEvent.CLICK, pauseGo);
addChild(pause);
graphics.moveTo(100,200);
graphics.lineStyle(0);
}
private function startGo(e:Event):void
{
rd.addEventListener(Event.ENTER_FRAME, move);
}
private function pauseGo(e:Event):void
{
rd.removeEventListener(Event.ENTER_FRAME, move);
}
private function move(evt:Event):void
{
rd.x=r - (r * Math.cos((t++) * Math.PI / 180)); //关键 坐标变化函式
rd.y=r * Math.sin((t++) * Math.PI / 180);
graphics.lineTo(rd.x+100,rd.y+100);//轨迹
}
}
}
分析如下图: