package  {
	
	 import flash.display.*; 

        import flash.events.*; 

        import flash.utils.getTimer; 

         

        public class AAGun extends MovieClip { 

                static const speed:Number = 150.0; 

                private var lastTime:int; // 控制移动的Timer 

                 

                public function AAGun() { 

                        // 枪的初始位置 

                        this.x = 150; 

                        this.y = 260; 

                         

                        //运动 

                        addEventListener(Event.ENTER_FRAME,moveGun); 

                } 



                public function moveGun(event:Event) { 

                        // 得到时差 

                        var timePassed:int = getTimer() - lastTime; 

                        lastTime += timePassed; 

                         

                        // 现在的位置 

                        var newx = this.x; 

                         

                        // 移动到左边 

                        if (MovieClip(parent).leftArrow) { 

                                newx -= speed*timePassed / 1000; 

                        } 

                         

                        // 移动到右边 

                        if (MovieClip(parent).rightArrow) { 

                                newx += speed*timePassed / 1000; 

                        } 

                         

                        // 检测边界 

                        if (newx < 10) newx = 10; 

                        if (newx > 540) newx = 540; 

                         

                        // 更新位置 

                        this.x = newx; 

                } 

                 

                // 移除屏幕上的炮和事件 

                public function deleteGun() { 

                        parent.removeChild(this); 

                        removeEventListener(Event.ENTER_FRAME,moveGun); 

                } 

        } 

	
}
