package {
// 主类 import flash.display.MovieClip; import flash.events.*; import flash.display.Shape; public class Main extends MovieClip { private var arrow:Arrow=new Arrow(); private var speed:Number;//速度 private var istart:Boolean = false;//是否开始 public function Main() { init(); } private function init():void { //轮盘 var disk:Disk=new Disk(10,150); addChild(disk); disk.x = stage.stageWidth / 2; disk.y = stage.stageHeight / 2; addChild(arrow); arrow.x = disk.x; arrow.y = disk.y; //创建按钮 var start_btn:CButton=new CButton("start"); start_btn.x=450; start_btn.y=20; var stop_btn:CButton=new CButton("stop"); stop_btn.x=450; stop_btn.y=45; addChild(start_btn); addChild(stop_btn); start_btn.addEventListener(MouseEvent.CLICK,onClick); stop_btn.addEventListener(MouseEvent.CLICK,onStopClick); } private function onClick(event:MouseEvent):void { startGame(); } private function onStopClick(event:MouseEvent):void { if (! istart)return; stopMove(); } private function startGame():void { if ( istart) return; istart = true; speed=50; addEventListener(Event.ENTER_FRAME,Run); } private function Run(event:Event):void { if (istart)move(); else stopMove(); } //运动 private function move():void { arrow.rotation += speed;//加上一个初始速度然后进行递减 speed-=0.5; if(speed<0)stopMove(); } //停止运行 private function stopMove():void { istart=false; removeEventListener(Event.ENTER_FRAME,Run); } } }
package { //箭头类 import flash.display.Sprite; public class Arrow extends Sprite { public function Arrow() { this.graphics.lineStyle(2,0xff0000); this.graphics.drawCircle(0,0,5); this.graphics.moveTo(0,0); this.graphics.lineTo(0,-90); this.graphics.moveTo(0,-90); this.graphics.lineTo(Math.cos(Math.PI/3)*8,-90+Math.sin(Math.PI/3)*8); this.graphics.moveTo(0,-90); this.graphics.lineTo(Math.cos(Math.PI-Math.PI/3)*8,-90+Math.sin(Math.PI-Math.PI/3)*8); } } }
package { //圆盘 import flash.display.Sprite; public class Disk extends Sprite { public function Disk(num:int,radius:Number) { if(num==0) return; this.graphics.lineStyle(0); this.graphics.drawCircle(0,0,radius); var perAngle:Number=360/num; for (var i:int=0; i<num; i++) { this.graphics.moveTo(0,0); this.graphics.lineTo(Math.cos(i*perAngle*Math.PI/180)*radius,Math.sin(i*perAngle*Math.PI/180)*radius); } } } }
package { import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.filters.GlowFilter; //测试按钮 public class CButton extends Sprite { public function CButton(label:String) { var btn_label:TextField=new TextField(); btn_label.text=label; btn_label.selectable=false; btn_label.autoSize=TextFieldAutoSize.CENTER; btn_label.mouseEnabled=false; btn_label.x=10; addChild(btn_label); this.graphics.beginFill(0xffffff); this.graphics.drawRect(0,0,50,20); this.graphics.endFill(); this.filters=[new GlowFilter(0x333333,0.3,3,3)]; this.buttonMode=true; } } }