[Stage3D] Feathersでシーン遷移! (2) ~ScreenNavigator, List~

Flash Player 11 から採用された Stage3D を学習するよ。 :bouzu:
Starling FrameworkFeathers でシーン遷移を試しちゃうんだからね。 :girl:

starling_feathers_screen32

:caution: 要 Flash Player 11.8 以上


This movie requires Flash Player 11.8.0

Main.as
package {

  import flash.display.Sprite;
  import flash.display.StageScaleMode;
  import flash.display.StageAlign;

  import starling.core.Starling;

  [SWF(backgroundColor="#FFFFFF", width="360", height="640", frameRate="60")]

  public class Main extends Sprite {
    // プロパティ
    private var starling:Starling;

    // コンストラクタ
    public function Main() {
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_LEFT;
      init();
    }

    // メソッド
    private function init():void {
      mouseEnabled = false;
      mouseChildren = false;
      starling = new Starling(MainView, stage, null, null);
      starling.enableErrorChecking = true;
      starling.start();
    }

  }

}



import flash.geom.Rectangle;
import starling.core.Starling;
import starling.display.Sprite;
import starling.events.Event;
import starling.events.ResizeEvent;
import starling.animation.Transitions;

import feathers.controls.ScreenNavigator;
import feathers.controls.ScreenNavigatorItem;
import feathers.motion.transitions.ScreenSlidingStackTransitionManager;
import feathers.system.DeviceCapabilities;
import feathers.themes.MetalWorksMobileTheme;

import feathers.screens.Screen1;
import feathers.screens.Screen21;
import feathers.screens.Screen22;


internal class MainView extends Sprite {
  // プロパティ
  private var navigator:ScreenNavigator;
  private var transition:ScreenSlidingStackTransitionManager;
  private static var screen1:String = "screen1";
  private static var screen21:String = "screen21";
  private static var screen22:String = "screen22";

  // コンストラクタ
  public function MainView() {
    addEventListener(Event.ADDED_TO_STAGE, init);
    addEventListener(Event.REMOVED_FROM_STAGE, remove);
  }

  // メソッド
  private function init(evt:Event):void {
    removeEventListener(Event.ADDED_TO_STAGE, init);
    DeviceCapabilities.dpi = 174;
    var theme:MetalWorksMobileTheme = new MetalWorksMobileTheme();
    navigator = new ScreenNavigator();
    addChild(navigator);

    navigator.addScreen(screen1, new ScreenNavigatorItem(new Screen1(), {onNext1: screen21, onNext2: screen22}));
    navigator.addScreen(screen21, new ScreenNavigatorItem(new Screen21(), {onBack: screen1}));
    navigator.addScreen(screen22, new ScreenNavigatorItem(new Screen22(), {onBack: screen1}));
    navigator.showScreen(screen1);

    transition = new ScreenSlidingStackTransitionManager(navigator);
    transition.duration = 0.4;
    transition.ease = Transitions.EASE_OUT;

  }
  private function remove(evt:Event):void {
    removeEventListener(Event.REMOVED_FROM_STAGE, remove);
  }
  override public function dispose():void {
    removeEventListener(Event.ADDED_TO_STAGE, init);
    removeEventListener(Event.REMOVED_FROM_STAGE, remove);
    super.dispose();
  }

}

Screen1.as (feathers.screens.Screen1.as)
package feathers.screens {

  import starling.display.Quad;
  import starling.events.Event;
  import starling.events.Touch;
  import starling.events.TouchEvent;
  import starling.events.TouchPhase;

  import feathers.controls.Screen;
  import feathers.controls.List;
  import feathers.data.ListCollection;

  import org.osflash.signals.Signal;
  import org.osflash.signals.ISignal;


  public class Screen1 extends Screen {
    // プロパティ
    protected var _onNext1:Signal = new Signal(Screen1);
    protected var _onNext2:Signal = new Signal(Screen1);
    private static var offset:uint = 35;

    // コンストラクタ
    public function Screen1() {
    }

    // メソッド
    override protected function initialize():void {
      var back:Quad = new Quad(360, 640, 0x3366CC);
      addChild(back);
      var items:Array = new Array();
      for (var n:uint = 0; n < 100; n++) {
        items.push({label: "item" + (n + 1)});
      }
      var collection:ListCollection = new ListCollection(items);
      var list:List = new List();
      addChild(list);

      list.width = 360;
      list.height = 580;
      list.y = offset;
      list.dataProvider = collection;
      list.addEventListener(Event.CHANGE, select);
    }
    override protected function draw():void {
    }
    private function select(evt:Event):void {
      var list:List = List(evt.target);
      var id:int = list.selectedIndex;
      if (id%2 == 0) {
        _onNext1.dispatch(this);
      } else {
        _onNext2.dispatch(this);
      }
    }
    public function get onNext1():ISignal {
      return _onNext1;
    }
    public function get onNext2():ISignal {
      return _onNext2;
    }

  }

}

Screen21.as (feathers.screens.Screen21.as)
package feathers.screens {

  import starling.display.Quad;
  import starling.events.Touch;
  import starling.events.TouchEvent;
  import starling.events.TouchPhase;

  import feathers.controls.Screen;
  import org.osflash.signals.Signal;
  import org.osflash.signals.ISignal;


  public class Screen21 extends Screen {
    // プロパティ
    protected var _onBack:Signal = new Signal(Screen21);

    // コンストラクタ
    public function Screen21() {
    }

    // メソッド
    override protected function initialize():void {
      var back:Quad = new Quad(360, 640, 0x66CCFF);
      addChild(back);
      addEventListener(TouchEvent.TOUCH, touch);
    }
    override protected function draw():void {
    }
    private function touch(evt:TouchEvent):void {
      var touch:Touch = evt.getTouch(this, TouchPhase.BEGAN);
      if (touch) {
        _onBack.dispatch(this);
      }
    }
    public function get onBack():ISignal {
      return _onBack;
    }

  }

}

Screen22.as (feathers.screens.Screen22.as)
package feathers.screens {

  import starling.display.Quad;
  import starling.events.Touch;
  import starling.events.TouchEvent;
  import starling.events.TouchPhase;

  import feathers.controls.Screen;
  import org.osflash.signals.Signal;
  import org.osflash.signals.ISignal;


  public class Screen22 extends Screen {
    // プロパティ
    protected var _onBack:Signal = new Signal(Screen22);

    // コンストラクタ
    public function Screen22() {
    }

    // メソッド
    override protected function initialize():void {
      var back:Quad = new Quad(360, 640, 0x66CC00);
      addChild(back);
      addEventListener(TouchEvent.TOUCH, touch);
    }
    override protected function draw():void {
    }
    private function touch(evt:TouchEvent):void {
      var touch:Touch = evt.getTouch(this, TouchPhase.BEGAN);
      if (touch) {
        _onBack.dispatch(this);
      }
    }
    public function get onBack():ISignal {
      return _onBack;
    }

  }

}


[修正] (13/08/08 Thu 13:29)
ScreenNavigatorItemの引数で、クラスではなくインスタンスを渡す方式に変更。
[修正] (13/09/26 Thu 00:17)
Starling 1.4 にバージョンアップ。Feathers 1.1.1 にバージョンアップ。
[修正] (13/11/12 Tue 19:13)
Starling 1.4.1 にバージョンアップ。
[修正] (13/11/28 Thu 23:20)
Feathers 1.2.0 にバージョンアップ。
[修正] (14/06/25 Wed 15:16)
Starling 1.5 にバージョンアップ。Feathers 1.3.0 にバージョンアップ。
[修正] (14/06/25 Wed 17:10)
Starling 1.5.1 にバージョンアップ。
[修正] (14/12/15 Mon 16:45)
Starling 1.6 にバージョンアップ。Feathers 2.0.1 にバージョンアップ。