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

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

starling_feathers_screen33

: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;
import feathers.screens.Screen23;


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";
  private static var screen23:String = "screen23";

  // コンストラクタ
  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, onNext3: screen23}));
    navigator.addScreen(screen21, new ScreenNavigatorItem(new Screen21(), {onBack: screen1}));
    navigator.addScreen(screen22, new ScreenNavigatorItem(new Screen22(), {onBack: screen1}));
    navigator.addScreen(screen23, new ScreenNavigatorItem(new Screen23(), {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 flash.utils.Dictionary;
  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.ScrollContainer;
  import feathers.layout.VerticalLayout;
  import feathers.events.FeathersEventType;

  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);
    protected var _onNext3:Signal = new Signal(Screen1);
    private static var offset:uint = 35;
    private var dictionary:Dictionary;
    private var scrolling:Boolean = false;

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

    // メソッド
    override protected function initialize():void {
      var back:Quad = new Quad(360, 640, 0x3366CC);
      addChild(back);
      var container:ScrollContainer = new ScrollContainer();
      addChild(container);

      container.width = 360;
      container.height = 580;
      container.y = offset;
      container.addEventListener(FeathersEventType.SCROLL_START, scroll);
      container.addEventListener(FeathersEventType.SCROLL_COMPLETE, scrolled);

      var layout:VerticalLayout = new VerticalLayout();
      layout.horizontalAlign = VerticalLayout.HORIZONTAL_ALIGN_CENTER;
      layout.gap = 10;

      container.layout = layout;
      var content1:Quad = new Quad(320, 160, 0x66CCFF);
      container.addChild(content1);
      content1.addEventListener(TouchEvent.TOUCH, touch);
      var content2:Quad = new Quad(320, 320, 0x66CC00);
      container.addChild(content2);
      content2.addEventListener(TouchEvent.TOUCH, touch);
      var content3:Quad = new Quad(320, 480, 0xCCCC00);
      container.addChild(content3);
      content3.addEventListener(TouchEvent.TOUCH, touch);
      dictionary = new Dictionary(true);
      dictionary[content1] = _onNext1;
      dictionary[content2] = _onNext2;
      dictionary[content3] = _onNext3;
    }
    override protected function draw():void {
    }
    private function scroll(evt:Event):void {
      scrolling = true;
    }
    private function scrolled(evt:Event):void {
      scrolling = false;
    }
    private function touch(evt:TouchEvent):void {
      var touch:Touch = evt.getTouch(this, TouchPhase.ENDED);
      if (touch) {
        if (!scrolling) {
          var _onNext:ISignal = dictionary[evt.target];
          _onNext1.dispatch(this);
        }
      }
    }
    public function get onNext1():ISignal {
      return _onNext1;
    }
    public function get onNext2():ISignal {
      return _onNext2;
    }
    public function get onNext3():ISignal {
      return _onNext3;
    }

  }

}

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;
    }

  }

}

Screen23.as (feathers.screens.Screen23.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 Screen23 extends Screen {
    // プロパティ
    protected var _onBack:Signal = new Signal(Screen23);

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

    // メソッド
    override protected function initialize():void {
      var back:Quad = new Quad(360, 640, 0xCCCC00);
      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:30)
ScreenNavigatorItemの引数で、クラスではなくインスタンスを渡す方式に変更。
[修正] (13/09/26 Thu 00:17)
Starling 1.4 にバージョンアップ。Feathers 1.1.1 にバージョンアップ。
[修正] (13/11/12 Tue 19:14)
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 にバージョンアップ。