4つのソースコードと画像を1つ用意します。
FeathersExample.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;
import starling.utils.HAlign;
import starling.utils.VAlign;
[SWF(width="960",height="640",frameRate="60",backgroundColor="#2f2f2f")]
public class FeathersExample extends Sprite
{
public function FeathersExample()
{
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 var _starling:Starling;
private function loaderInfo_completeHandler(event:Event):void
{
var exampleIndex:int;
Starling.handleLostContext = true;
Starling.multitouchEnabled = true;
exampleIndex = 0;
switch(exampleIndex)
{
case 0:
this._starling = new Starling(ButtonExample, this.stage);
break;
case 1:
this._starling = new Starling(ListExample, this.stage);
break;
}
this._starling.enableErrorChecking = false;
this._starling.showStatsAt(HAlign.RIGHT,VAlign.BOTTOM,2);
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();
}
}
}
ButtonExample.as
package
{
import feathers.controls.Button;
import feathers.controls.Callout;
import feathers.controls.Label;
import feathers.themes.*;
import flash.display.Bitmap;
import starling.display.Image;
import starling.display.Sprite;
import starling.events.Event;
import starling.textures.Texture;
public class ButtonExample extends Sprite
{
[Embed(source='./icon.png')]
public var ButtonIconSkin:Class;
public function ButtonExample()
{
this.addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
}
protected var theme:MetalWorksMobileTheme;
protected var button:Button;
protected function addedToStageHandler(event:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
var icon:Bitmap = new ButtonIconSkin();
var themeIndex:int;
themeIndex = 0;
switch(themeIndex)
{
case 0:
this.theme = new MetalWorksMobileTheme(this.stage);
break;
case 1:
//this.theme = new AeonDesktopTheme(this.stage);
break;
case 2:
//this.theme = new ExtendMetalWorksTheme(this.stage);
break;
}
this.button = new Button();
this.button.label = "クリック";
this.button.nameList.add(ExtendMetalWorksTheme.ALTERNATE_NAME_MY_CUSTOM_BUTTON);
this.button.defaultIcon = new Image(Texture.fromBitmapData(icon.bitmapData));
this.button.iconPosition = Button.ICON_POSITION_TOP;
this.button.gap = 0;
this.button.horizontalAlign = Button.HORIZONTAL_ALIGN_LEFT;
this.button.verticalAlign = Button.VERTICAL_ALIGN_MIDDLE;
this.button.width = 200;
this.button.height = 80;
this.button.labelOffsetX = this.button.iconOffsetX + icon.width;
this.button.labelOffsetY = -(this.button.height/2);
this.button.addEventListener(Event.TRIGGERED, button_triggeredHandler);
this.button.addEventListener(Event.CHANGE, button_changeHandler);
this.addChild(this.button);
this.button.validate();
this.button.x = (this.stage.stageWidth - this.button.width) / 2;
this.button.y = (this.stage.stageHeight - this.button.height) / 2;
}
protected function button_triggeredHandler(event:Event):void
{
const label:Label = new Label();
label.text = "Hi, I'm Feathers!\nHave a nice day.";
Callout.show(label, this.button);
}
private function button_changeHandler(event:Event):void
{
var button:Button = event.currentTarget as Button;
trace( "button.isSelected has changed:",button.isSelected);
}
}
}

0 件のコメント:
コメントを投稿