Access stage from Model: Hack

elliot's Avatar


01 Sep, 2012 01:41 AM

Here's a little hack to allow stage reference from within classes that don't normally have a reference to the stage (e.g., Models). It works by enabling injection of the stage into any RL class.

Yes, there are better (practice) ways to do this kind of thing, but I wanted to share the hack anyway.

Let's say you want to notify the app of a change to the device orientation:

// in the Context injector.mapValue( Stage, contextView.stage );

// in a Model [Inject] var stage : Stage;
... // event handlers for these listeners would trigger appropriate Commands to notify the rest of the app about the events. stage.addEventListener( Stage.onOrientationChange, onOrientationChange );
stage.addEventListener( Event.MOUSE_LEAVE, onMouseLeave );

... or, maybe you want to reference Stage properties from within a Command? Just map it and inject it!

[Inject] var stage : Stage;
... override public function execute() : void

trace( "WTF, stage property reference from a Command?!:", stage.fullScreenWidth );


  1. Ondina D.F. closed this discussion on 03 Sep, 2012 08:57 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac