PV3D入门程序-图像移动实例

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

	public class FlexTest extends Sprite
	{
		private var circle_sprite:Sprite;
		private var isUP:Boolean;
		private var isDown:Boolean;
		private var isLeft:Boolean;
		private var isRight:Boolean;
		private const  MOVE_SPEED:int=2; 
		
		public function FlexTest()
		{
			circle_sprite = new Sprite();
			circle_sprite.graphics.beginFill(0x000000);
			circle_sprite.graphics.drawCircle(100,100,20);
			circle_sprite.graphics.endFill();
			this.addChild(circle_sprite);
			stage.addEventListener(KeyboardEvent.KEY_DOWN,getKeyDown);
			stage.addEventListener(KeyboardEvent.KEY_UP,getKeyUp);
			stage.addEventListener(Event.ENTER_FRAME,getEnterFrame);
		}
		
               /**
              *侦听键盘按下事件   
               */
		private function getKeyDown(event:KeyboardEvent):void
		{
				if(event.keyCode == 38){
					isUP = true;
				}
				if(event.keyCode == 40){
					isDown = true;
				}
				
				if(event.keyCode == 37){
					isLeft =true;
				}
				
				if(event.keyCode ==39){
					isRight = true;
				}
				
		}
		
              /**
                 *侦听键盘松开事件
                 */
		private function getKeyUp(event:KeyboardEvent):void
		{
				if(event.keyCode == 38){
					isUP = false;
				}
				if(event.keyCode == 40){
					isDown = false;
				}
				
				if(event.keyCode == 37){
					isLeft =false;
				}
				
				if(event.keyCode ==39){
					isRight = false;
				}
				
		}
		/**
                *改变坐标
                */
		private function getEnterFrame(event:Event):void
		{
			if(isUP){
				circle_sprite.y -=MOVE_SPEED;
			}
			if(isRight){
				circle_sprite.x +=MOVE_SPEED;
			}
			if(isDown){
				circle_sprite.y +=MOVE_SPEED;
			}
			if(isLeft){
				circle_sprite.x -=MOVE_SPEED;
			}
		}	
	}
}

你可能感兴趣的:(Flash,UP)