tomo.mobi

Representation design of material


stageサイズのメモ書き

コードのメモです。

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.display.StageDisplayState; 
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flash.display.Shape;
	
	public class Sample extends Sprite
	{
		private var ball:Sprite = new Sprite();
		private var bg:Shape = new Shape();
		private var vectorX:Number = 10;
		private var vectorY:Number = 10;
		private var timer:Timer = new Timer(1000);
		private var width:Number = 0;//幅
		private var height:Number = 0;//高さ

		public function Sample()
		{
			super();
			
			// autoOrients をサポート
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
			
			//stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE
			//の記述の後でないと正確な値はとれない
			width = stage.stageWidth;// 幅
			height = stage.stageHeight;// 高さ

			bg.graphics.clear();
			bg.graphics.beginFill(0xffff00);
			bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
			bg.graphics.endFill();
			
			addChild(bg);

			ball.graphics.beginFill(0xff0000);
			ball.graphics.drawCircle(0,0,50);
			ball.graphics.endFill();
			
			ball.x = 100;
			ball.y = 100;
			
			timer.addEventListener(TimerEvent.TIMER, loop);
			timer.start();
			
			function loop(e:TimerEvent):void {
				onSprite();
			}

			function onSprite():void {
				removeEventListener(Event.ENTER_FRAME, sprite_enterFrameHandler);
				addEventListener(Event.ENTER_FRAME, sprite_enterFrameHandler);
			}

		}
		protected function sprite_enterFrameHandler(event:Event):void
		{
			if(ball.x > width || ball.x < 0){
				vectorX = -vectorX;
			}
			if(ball.y > height || ball.y < 0){
				vectorY = -vectorY;
			}
			ball.x += vectorX;
			ball.y += vectorY;
			stage.addChild(ball);
			
		}

	}
}

http://help.adobe.com/ja_JP/air/html/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7e06.html