Created
April 26, 2016 13:10
-
-
Save YuukiOgino/6b0a77f7bbed030f16ce29cbf3214c7c to your computer and use it in GitHub Desktop.
Robotlegs2を用いたStage3D(Staling)開発 ref: http://qiita.com/YuukiOgino/items/672fd96a21a516a4cc2f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context.install(MVCSBundle, StarlingViewMapExtension); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context.configure(MainConfig, starling); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mediatorMap.map(UserStarlingView).toMediator(UserStarlingMediator); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserStarlingMediator extends StarlingMediator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* フレームワーク Robotlegs2 サンプルプロジェクト | |
* as3であればGraphics,Stage3D、Flexで使用可能 | |
* このプロジェクトはStage3D(Starling)で記載 | |
* | |
* @author ogino | |
*/ | |
public class Main extends Sprite | |
{ | |
//----------------------------------------------------- | |
//コンポーネント | |
//----------------------------------------------------- | |
/** スターリング */ | |
private var starling:Starling; | |
//----------------------------------------------------- | |
//コンストラクタ | |
//----------------------------------------------------- | |
/** | |
* コンストラクタ | |
*/ | |
public function Main():void | |
{ | |
if (stage) init(); | |
else addEventListener(Event.ADDED_TO_STAGE, init); | |
} | |
//----------------------------------------------------- | |
//イベントハンドラー | |
//----------------------------------------------------- | |
/** | |
* 初期化 | |
* | |
* @param e Event | |
*/ | |
private function init(e:Event = null):void | |
{ | |
removeEventListener(Event.ADDED_TO_STAGE, init); | |
starling = new Starling(UserStarlingView, stage); | |
if (starling.isStarted) | |
starling.stage.addChild(starling.root);// starlingが起動しているなら、stageにaddchildすればRobotlegsで感知できる | |
else | |
starling.start(); // Starling起動 | |
// Robotlegs2を起動するための設定 | |
// MVCSBundle,StarlingViewMapExtensionをセット | |
// コンフィグクラス, Starlingをセット | |
// 最後にコンテキストビューをセットし、初期化処理を実行 | |
var context:Context = new Context(); | |
// おまじない StarlingViewMapExtensionも追加でインストールする | |
context.install(MVCSBundle, StarlingViewMapExtension); | |
// コンフィグクラスをセット この時、Starlingもセットする | |
context.configure(MainConfig, starling); | |
// コンテキストビューとしてこの画面をセット | |
context.configure(new ContextView(this)); | |
// Robotlegs2初期化 | |
context.initialize(); | |
addEventListener(Event.REMOVED_FROM_STAGE, removeEventHandler); | |
} | |
/** | |
* ステージから削除された場合のイベントハンドラー | |
* @param e | |
*/ | |
private function removeEventHandler(e:Event):void | |
{ | |
removeEventListener(Event.REMOVED_FROM_STAGE, removeEventHandler); | |
// このどちらかでMediatorのdestroyが呼ばれる | |
starling.root.removeFromParent(); | |
starling.root.dispose(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* メイン画面のコンフィギュレーションを行うクラス | |
* | |
* このクラスで以下の設定を実行しています。 | |
* ・UserModel はシングルトンである | |
* UserStarlingView の対になるメディエータは UserStarlingMediator である | |
* ・メディエーターでUserChangeEvent.USER_CHANGEが呼ばれた場合、UserCommondを実行する | |
* | |
* @author ogino | |
*/ | |
public class MainConfig implements IConfig | |
{ | |
//----------------------------------------------------- | |
//プロパティ | |
//----------------------------------------------------- | |
[Inject] | |
/** インジェクター */ | |
public var injector:IInjector; | |
[Inject] | |
/** メディエーターマップ */ | |
public var mediatorMap:IMediatorMap; | |
[Inject] | |
/** イベントコマンドマップ */ | |
public var commandMap:IEventCommandMap; | |
[Inject] | |
/** コンテキストビュー */ | |
public var contextView:ContextView; | |
//----------------------------------------------------- | |
//メソッド | |
//----------------------------------------------------- | |
/** | |
* コンフィギュレーション実行 | |
*/ | |
public function configure():void | |
{ | |
// おまじない | |
// UserModel はシングルトンである | |
injector.map(UserModel, "modelName").asSingleton(); | |
injector.map(UserModel).asSingleton(); | |
// UserStarlingView の対になるメディエータは UserStarlingMediator である | |
mediatorMap.map(UserStarlingView).toMediator(UserStarlingMediator); | |
// メディエーターでUserChangeEvent.USER_CHANGEが呼ばれた場合、UserCommondを実行する | |
commandMap.map(UserChangeEvent.USER_CHANGE).toCommand(UserCommand); | |
// このような形で値を注入することも可能 | |
//var user:UserModel = new UserModel(); | |
//injector.map(UserModel, "modelName").toValue(user); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ユーザー画面のメディエータクラス | |
* UserModelとUserStarlingViewの仲介を行う | |
* 「ユーザの名前が変更された」というきっかけで「ビューにその名前を反映する」タスクを実行するだけのクラス | |
* | |
* @author ogino | |
*/ | |
public class UserStarlingMediator extends StarlingMediator | |
{ | |
//----------------------------------------------------- | |
//コンポーネント | |
//----------------------------------------------------- | |
[Inject] | |
/** ユーザ画面 */ | |
public var view:UserStarlingView; | |
//----------------------------------------------------- | |
//プロパティ | |
//----------------------------------------------------- | |
[Inject(name="modelName")] | |
/** ユーザモデル */ | |
public var user:UserModel; | |
//----------------------------------------------------- | |
//オーバーライドしたメソッド | |
//----------------------------------------------------- | |
/** | |
* @inheritDoc | |
*/ | |
public override function initialize():void | |
{ | |
// 名前が変更されたときに呼び出すメソッドをセット | |
user.addEventListener(Event.CHANGE, changeView); | |
view.addEventListener(UserChangeStalringEvent.USER_CHANGE, view_userChange); | |
} | |
/** | |
* @inheritDoc | |
*/ | |
public override function destroy():void | |
{ | |
// 登録したメソッドを削除 | |
user.removeEventListener(Event.CHANGE, changeView); | |
view.removeEventListener(UserChangeStalringEvent.USER_CHANGE, view_userChange); | |
} | |
//----------------------------------------------------- | |
//イベントハンドラー | |
//----------------------------------------------------- | |
/** | |
* 画面更新 | |
* | |
* @param e Event | |
*/ | |
public function changeView(e:Event):void | |
{ | |
view.nameChange(user.name); | |
} | |
/** | |
* 画面変更通知イベントハンドラー | |
* | |
* @param e | |
*/ | |
private function view_userChange(e:UserChangeStalringEvent):void | |
{ | |
// コマンドを呼び出すイベントを作成 | |
var newEvent:UserChangeEvent = new UserChangeEvent(UserChangeEvent.USER_CHANGE); | |
// フレームワークに通知 このイベントに紐付けられたCommandクラスが呼ばれる | |
eventDispatcher.dispatchEvent(newEvent); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ユーザーがデーターを変更した時のイベント | |
* Staling用 | |
* | |
* @author ogino | |
*/ | |
public class UserChangeStalringEvent extends Event | |
{ | |
//----------------------------------------------------- | |
//イベント定数 | |
//----------------------------------------------------- | |
/** ユーザー変更 */ | |
public static const USER_CHANGE:String = "userChange"; | |
//----------------------------------------------------- | |
//コンストラクタ | |
//----------------------------------------------------- | |
/** | |
* コンストラクタ | |
* | |
* @param type | |
* @param bubbles | |
* @param data | |
*/ | |
public function UserChangeStalringEvent(type:String, bubbles:Boolean=false, data:Object=null) | |
{ | |
super(type, bubbles, data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment