ActionScript 3 (Flash/AIR): Starling Hello World

ActionScript 3: Main.as

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	
	import jp.feb19.StarlingMain;
	
	[SWF(frameRate="60", width="640", height="960")]
	public class PuzzleStage extends Sprite
	{
		public function PuzzleStage()
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.frameRate = 60;
			
			addEventListener(Event.ADDED_TO_STAGE, _addedToStageHandler);
		}
		
		protected function _addedToStageHandler(event:Event):void
		{
			// メイン開始
			new StarlingMain(stage);
		}
	}
}

ActionScript 3: StarlingMain.as

package jp.feb19
{
	import flash.display.Stage;
	import flash.geom.Rectangle;
	
	import starling.core.Starling;

	public class StarlingMain
	{
		private var _starling:Starling;
		
		public function StarlingMain(mainStage:Stage)
		{
			//Starlingを初期化
			Starling.handleLostContext = true;
			_starling = new Starling(RootView, mainStage, new Rectangle(0, 0, mainStage.stageWidth, mainStage.stageHeight));
			_starling.start();
			
		}
	}
}

ActionScript 3: RootView.as

package jp.feb19
{
	import starling.display.Quad;
	import starling.display.Sprite;
	
	public class RootView extends Sprite
	{
		public function RootView()
		{
			super();
			addEventListener(Event.ADDED_TO_STAGE, _addedToStageHandler);
		}
		
		private function _addedToStageHandler(event:Event):void
		{
			var quad:Quad = new Quad(320, 320, 0xff0000);
			addChild(quad);
		}
	}
}

wmode=’direct’ を SWF 埋め込み用の HTML に追加するのを忘れずに。