Last active
December 17, 2015 09:19
-
-
Save patrixd/5586071 to your computer and use it in GitHub Desktop.
Basic example using Robotlegs2 and Starling. Note: to use Inject in Robotlegs, the class that use them must exist in the context. It was weird to me because I came of Parsley. In Parsley you only declare what to inject you do not declare who inject them too. This example also has an splash in pure actionscript.
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
package { | |
// imports ... | |
public class AppConfig implements IConfig | |
{ | |
[Inject] | |
public var context:IContext; | |
[Inject] | |
public var commandMap:ISignalCommandMap; | |
[Inject] | |
public var mediatorMap:IMediatorMap; | |
[Inject] | |
public var injector:Injector; | |
[Inject] | |
public var logger:ILogger; | |
[Inject] | |
public var contextView:ContextView; | |
[Inject] | |
public var dispatcher:IEventDispatcher; | |
public function configure():void { | |
// Configure logger. | |
context.logLevel = LogLevel.DEBUG; | |
logger.info( "configuring application" ); | |
// Map views injections | |
injector.map( ModelLocator ).asSingleton | |
injector.map( NavigateMediator ).asSingleton(); | |
injector.map( TemplateManager ).asSingleton(); | |
injector.map( UpdateManager ).asSingleton(); | |
// Map views. | |
mediatorMap.map( RootScreen ).toMediator( RootController ); | |
// Start. | |
context.afterInitializing( init ); | |
} | |
private function init():void { | |
logger.info( "application ready" ); | |
} | |
} | |
} |
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
package { | |
//import .. | |
import flash.display.Sprite; | |
import starling.core.Starling; | |
import robotlegs.bender.framework.impl.Context; | |
import robotlegs.bender.extensions.contextView.ContextView; | |
import robotlegs.extensions.starlingViewMap.StarlingViewMapExtension; | |
import robotlegs.bender.bundles.mvcs.MVCSBundle; | |
import bundles.SignalCommandMapBundle; | |
[SWF(frameRate="60", backgroundColor="#fefefe")] | |
public class PatProject extends Sprite { | |
[Embed(source="assets/splash.jpg")] | |
private static var Background:Class; | |
private var _starling:Starling; | |
private var _context:Context; | |
private var _splash:Bitmap; | |
public function PatProject() { | |
var viewPort:Rectangle = new Rectangle(0, 0, stage.fullScreenWidth, stage.fullScreenHeight); | |
_splash = new Background(); | |
_splash.x = viewPort.x; | |
_splash.y = viewPort.y; | |
_splash.width = viewPort.width; | |
_splash.height = viewPort.height; | |
_splash.smoothing = true; | |
addChild(_splash); | |
// STARLING INITIALIZATION | |
_starling = new Starling(RootScreen, stage, viewPort); | |
_starling.simulateMultitouch = false; | |
_starling.enableErrorChecking = false; | |
_starling.showStats = true; | |
_starling.addEventListener(starling.events.Event.ROOT_CREATED, onStarlingCreated); | |
// ROBOTLEGS INITIALIZATION | |
_context = new Context(); | |
_context.install( MVCSBundle, StarlingViewMapExtension, SignalCommandMapBundle ); | |
_context.configure( AppConfig, this, _starling ); | |
_context.configure( new ContextView( this ) ); | |
NativeApplication.nativeApplication.addEventListener( | |
flash.events.Event.ACTIVATE, function (e:*):void { _starling.start(); }); | |
NativeApplication.nativeApplication.addEventListener( | |
flash.events.Event.DEACTIVATE, function (e:*):void { _starling.stop(); }); | |
} | |
function onInitialViewLoaded():void { | |
removeChild(_splash); | |
} | |
function onStarlingCreated():void { | |
var rootScreen:RootScreen = _starling.root as RootScreen; | |
rootScreen.onReady.add(onInitialViewLoaded); | |
rootScreen.start(_starling.stage); | |
_starling.start(); | |
} | |
} | |
} |
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
package application { | |
import feathers.controls.ScreenNavigator; | |
//import ... | |
import org.osflash.signals.Signal; | |
import robotlegs.extensions.starlingViewMap.impl.StarlingMediator; | |
import starling.display.Sprite; | |
import starling.display.Stage; | |
public class RootController extends StarlingMediator { | |
//Because of this I need RootController as mediator. I could not get Inject work in another way | |
[Inject] | |
public var modelLocator:ModelLocator; | |
[Inject] | |
public var navigateMediator:NavigateMediator; //add the screens with starling that will have the app | |
[Inject] | |
public var templateManager:TemplateManager; | |
[Inject] | |
public var updateManager:UpdateManager; | |
[Inject] | |
public var mainView:RootScreen; | |
private var _stage:Stage; | |
public function get navigator():ScreenNavigator { return navigateMediator.navigator; } | |
//RobotLegs initialize it | |
override public function initialize(): void { | |
mainView.onStarted.add(start); | |
} | |
public function start(stage:Stage): void { | |
_stage = stage; | |
templateManager.initialize(_stage); | |
mainView.addEventListener(Event.ADDED_TO_STAGE, onAddedToStageHandler); | |
mainView.addChild(navigator); | |
navigator.showScreen(NavigateMediator.LOGIN_VIEW); | |
mainView.ready(); //will hide splash | |
} | |
} | |
} |
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
package presentation | |
{ | |
import org.osflash.signals.Signal; | |
import starling.display.Sprite; | |
import starling.display.Stage; | |
public class RootScreen extends Sprite | |
{ | |
private var _onStarted:Signal; | |
public function get onStarted():Signal { return _onStarted; } | |
private var _onReady:Signal; | |
public function get onReady():Signal { return _onReady; } | |
public function RootScreen() | |
{ | |
_onReady = new Signal(); | |
_onStarted = new Signal(); | |
} | |
public function start(stage:Stage) | |
{ | |
_onStarted.dispatch(stage); | |
} | |
public function ready() { | |
onReady.dispatch(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment