2013年2月5日火曜日

Feathers ScreenExample 作成3

Sub2ChildScreen.as
package screens
{
 import feathers.controls.Button;
 import feathers.controls.Header;
 import feathers.controls.Label;
 import feathers.controls.Screen;
 import feathers.controls.ScrollContainer;
 import feathers.layout.AnchorLayout;
 import feathers.layout.VerticalLayout;

 import starling.display.DisplayObject;
 import starling.events.Event;

 public class Sub2ChildScreen extends Screen
 {
  private var _container:ScrollContainer;
  private var _header:Header;
  private var _backButton:Button;

  public var horizontalAlign:String = VerticalLayout.HORIZONTAL_ALIGN_LEFT;
  public var verticalAlign:String = VerticalLayout.VERTICAL_ALIGN_TOP;
  public var gap:Number = 2;
  public var paddingTop:Number = 0;
  public var paddingRight:Number = 0;
  public var paddingBottom:Number = 0;
  public var paddingLeft:Number = 0;

  public function Sub2ChildScreen()
  {
   super();
  }

  override protected function initialize():void
  {
   this._container = new ScrollContainer();
   this._container.layout = new AnchorLayout();
   this._container.verticalScrollPolicy = ScrollContainer.SCROLL_POLICY_ON;
   this._container.snapScrollPositionsToPixels = true;
   this.addChild(this._container);

   this._header = new Header();
   this._header.title = "Sub2 ChildScreen";
   this.addChild(this._header);

   this._backButton = new Button();
   this._backButton.label = "Back";
   this._backButton.addEventListener(Event.TRIGGERED, backButton_triggeredHandler);

   this._header.leftItems = new &ltdisplayobject>
    [
    this._backButton
    ];

   this.backButtonHandler = this.onBackButton;

   var label:Label = new Label();
   label.text = "Sub2のサブビューです";
   this._container.addChild(label);
  }

  override protected function draw():void
  {
   this._header.width = this.actualWidth;
   this._header.validate();

   this._container.y = this._header.height;
   this._container.width = this.actualWidth;
   this._container.height = this.actualHeight - this._container.y;
  }

  private function onBackButton():void
  {
   this.owner.showScreen(Main.SUB2_SCREEN);
  }

  private function backButton_triggeredHandler(event:Event):void
  {
   this.onBackButton();
  }
 }
}
Sub2Screen.as
package screens
{
 import feathers.controls.Button;
 import feathers.controls.Header;
 import feathers.controls.Screen;
 import feathers.controls.ScrollContainer;
 import feathers.layout.VerticalLayout;

 import starling.display.DisplayObject;
 import starling.display.Quad;
 import starling.events.Event;

 public class Sub2Screen extends Screen
 {
  public static const SHOW_CHILD_SCREEN:String = "showChildScreen";

  private var _container:ScrollContainer;
  private var _header:Header;
  private var _backButton:Button;
  private var _childButton:Button;

  public var horizontalAlign:String = VerticalLayout.HORIZONTAL_ALIGN_LEFT;
  public var verticalAlign:String = VerticalLayout.VERTICAL_ALIGN_TOP;
  public var gap:Number = 2;
  public var paddingTop:Number = 0;
  public var paddingRight:Number = 0;
  public var paddingBottom:Number = 0;
  public var paddingLeft:Number = 0;

  public function Sub2Screen()
  {
   super();
  }

  override protected function initialize():void
  {
   const layout:VerticalLayout = new VerticalLayout();
   layout.gap = this.gap;
   layout.paddingTop = this.paddingTop;
   layout.paddingRight = this.paddingRight;
   layout.paddingBottom = this.paddingBottom;
   layout.paddingLeft = this.paddingLeft;
   layout.horizontalAlign = this.horizontalAlign;
   layout.verticalAlign = this.verticalAlign;

   this._container = new ScrollContainer();
   this._container.layout = layout;
   this._container.verticalScrollPolicy = ScrollContainer.SCROLL_POLICY_ON;
   this._container.snapScrollPositionsToPixels = true;
   this.addChild(this._container);

   this._header = new Header();
   this._header.title = "Sub2 Screen";
   this.addChild(this._header);

   this._backButton = new Button();
   this._backButton.label = "Back";
   this._backButton.addEventListener(Event.TRIGGERED, backButton_triggeredHandler);

   this._header.leftItems = new &ltdisplayobject>
    [
    this._backButton
    ];

   this._childButton = new Button();
   this._childButton.label = "ChildScreen";
   this._childButton.addEventListener(Event.TRIGGERED, childButton_triggeredHandler);

   this._header.rightItems = new &ltdisplayobject>
    [
    this._childButton
    ];

   this.backButtonHandler = this.onBackButton;

   var redQuad:Quad = new Quad(100,100,0xff0000);
   var greenQuad:Quad = new Quad(100,100,0x00ff00);
   var blueQuad:Quad = new Quad(100,100,0x0000ff);

   this._container.addChild(redQuad);
   this._container.addChild(greenQuad);
   this._container.addChild(blueQuad);
  }

  private function childButton_triggeredHandler():void
  {
   this.dispatchEventWith(SHOW_CHILD_SCREEN);
  }

  override protected function draw():void
  {
   this._header.width = this.actualWidth;
   this._header.validate();

   this._container.y = this._header.height;
   this._container.width = this.actualWidth;
   this._container.height = this.actualHeight - this._container.y;
  }

  private function onBackButton():void
  {
   this.owner.showScreen(Main.MAIN_MENU);
  }

  private function backButton_triggeredHandler(event:Event):void
  {
   this.onBackButton();
  }
 }
}
StarlingFramework,Feathers,FeathersThemeの
Flexライブラリプロジェクトの登録を行います。(リンク先へ)
ビルドを行います。

0 件のコメント:

コメントを投稿