2013年2月5日火曜日

Feathers ScreenExample 作成1

プロジェクト名はFeathersScreenです。
パッケージの構成です。

FeathersScreenExample.as
package
{
 import flash.display.Sprite;
 import flash.display.StageAlign;
 import flash.display.StageScaleMode;
 import flash.events.Event;
 import flash.geom.Rectangle;

 import starling.core.Starling;

 [SWF(width="960",height="640",frameRate="60",backgroundColor="#2f2f2f")]
 public class FeathersScreenExample extends Sprite
 {
  private var _starling:Starling;        

  public function FeathersScreenExample()
  {
   if(this.stage)
   {
    this.stage.scaleMode = StageScaleMode.NO_SCALE;
    this.stage.align = StageAlign.TOP_LEFT;
   }
   this.mouseEnabled = this.mouseChildren = false;
   this.loaderInfo.addEventListener(Event.COMPLETE, loaderInfo_completeHandler);
  }

  private function loaderInfo_completeHandler(event:Event):void
  {
   Starling.handleLostContext = true;
   Starling.multitouchEnabled = true;
   this._starling = new Starling(Main, this.stage);
   this._starling.enableErrorChecking = false;
   this._starling.start();

   this.stage.addEventListener(Event.RESIZE, stage_resizeHandler, false, int.MAX_VALUE, true);
   this.stage.addEventListener(Event.DEACTIVATE, stage_deactivateHandler, false, 0, true);
  }

  private function stage_resizeHandler(event:Event):void
  {
   this._starling.stage.stageWidth = this.stage.stageWidth;
   this._starling.stage.stageHeight = this.stage.stageHeight;

   const viewPort:Rectangle = this._starling.viewPort;
   viewPort.width = this.stage.stageWidth;
   viewPort.height = this.stage.stageHeight;
   try
   {
    this._starling.viewPort = viewPort;
   }
   catch(error:Error) {}
  }

  private function stage_deactivateHandler(event:Event):void
  {
   this._starling.stop();
   this.stage.addEventListener(Event.ACTIVATE, stage_activateHandler, false, 0, true);
  }

  private function stage_activateHandler(event:Event):void
  {
   this.stage.removeEventListener(Event.ACTIVATE, stage_activateHandler);
   this._starling.start();
  }
 }
}
Main.as
package 
{
 import feathers.controls.ScreenNavigator;
 import feathers.controls.ScreenNavigatorItem;
 import feathers.controls.ScrollContainer;
 import feathers.motion.transitions.ScreenSlidingStackTransitionManager;
 import feathers.themes.MetalWorksMobileTheme;

 import screens.MainMenuScreen;
 import screens.Sub1Screen;
 import screens.Sub2ChildScreen;
 import screens.Sub2Screen;

 import starling.display.Sprite;
 import starling.events.Event;

 public class Main extends Sprite
 {
  public static const MAIN_MENU:String = "mainMenu";
  public static const SUB1_SCREEN:String = "sub1Screen";
  public static const SUB2_SCREEN:String = "sub2Screen";
  public static const SUB2_CHILD_SCREEN:String = "sub2ChildScreen";

  private var _theme:MetalWorksMobileTheme;
  private var _container:ScrollContainer;
  private var _navigator:ScreenNavigator;
  private var _menu:MainMenuScreen;
  private var _transitionManager:ScreenSlidingStackTransitionManager;

  private static const MAIN_MENU_EVENTS:Object =
   {
    showSub1Screen: SUB1_SCREEN,
    showSub2Screen: SUB2_SCREEN
  }

  public function Main()
  {
   super();
   this.addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
  }

  private function addedToStageHandler(event:Event):void
  {
   this._theme = new MetalWorksMobileTheme(this.stage);

   this._navigator = new ScreenNavigator();

   this._navigator.addScreen(SUB1_SCREEN,new ScreenNavigatorItem(Sub1Screen));

   this._navigator.addScreen(SUB2_SCREEN,
    new ScreenNavigatorItem(Sub2Screen,{showChildScreen:SUB2_CHILD_SCREEN}));
   this._navigator.addScreen(SUB2_CHILD_SCREEN,new ScreenNavigatorItem(Sub2ChildScreen));

   this._navigator.addScreen(MAIN_MENU,new ScreenNavigatorItem(MainMenuScreen,MAIN_MENU_EVENTS));

   this.addChild(this._navigator);

   this._transitionManager = new ScreenSlidingStackTransitionManager(this._navigator);
   this._transitionManager.duration = 0.4;

   this._navigator.showScreen(MAIN_MENU);
  }
 }
}

0 件のコメント:

コメントを投稿