엔터프레임 이벤트에서 시계바늘을 회전하면서 그려줍니다.
회전할 때는 오브젝트를 회전하는 방법도 있지만,
코드 애니메이션에서는 삼각함수를 이용하여 특정좌표를 일정 각도(라디안)만큼 회전한 좌표를 구합니다.
코사인함수는 y, 싸인함수는 x 좌표를 구하지요. (중학교때 배운듯)



package {
import flash.display.Sprite;
import flash.events.Event;

    [SWF(width=800,height=600,backgroundColor=0xFFFFFF)]
public class AsExam10_9 extends Sprite {
private var radius:Number = 200;
private var ang:Number = 0;
public function AsExam10_9() {
stage.addEventListener(Event.ENTER_FRAME, clickHandler);
}
private function clickHandler(event:Event):void {
ang += 3 * Math.PI/180;
var dx:Number = Math.cos(ang)*radius;
var dy:Number = Math.sin(ang)*radius;
            this.graphics.clear();
            this.graphics.moveTo(stage.stageWidth/2, stage.stageHeight/2);
            this.graphics.lineStyle(1, 0xFF0000);
            // 마우스 위치에서 radius만큼 떨어진곳과 연결 직선을 그린다.
            this.graphics.lineTo(dx+stage.stageWidth/2, dy+stage.stageHeight/2);
            this.graphics.beginFill(0x0000FF);
            // 마우스 위치에서 radius만큼 떨어진 곳에 원을 그린다.
            this.graphics.drawCircle(dx+stage.stageWidth/2, dy+stage.stageHeight/2, 20);
}
}
}
1.jpg

profile