Created
January 29, 2013 13:24
-
-
Save Stray/4664190 to your computer and use it in GitHub Desktop.
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
// in the context | |
injector.map(AssetRequestSignal).asSingleton(); | |
// in the model/service | |
[Inject] | |
public var assetRequestSignal:AssetRequestSignal; | |
function setUp():void | |
{ | |
assetRequestSignal.add( handleRequest ); | |
} | |
function handleRequest(assetID:String, responseSignal:OnceSignal):void | |
{ | |
if(_cachedAssetsByID[assetID]) | |
responseSignal.dispatch(_cachedAssetsByID[assetID]); | |
else | |
loadAsset(assetID, responseSignal); | |
} | |
function loadAsset(assetID:String, responseSignal:OnceSignal):void | |
{ | |
// load the assets and then respond when loaded | |
} | |
// in the view: | |
[Inject] | |
public var assetRequestSignal:AssetRequestSignal; | |
private var assetResponseSignal:OnceSignal; | |
function init():void | |
{ | |
assetResponseSignal = new OnceSignal(DisplayObject); | |
assetResponseSignal.addOnce( handleAssets ); | |
assetRequestSignal.dispatch( someSortOfAssetID, assetResponseSignal ); | |
} | |
function handleAssets(asset:DisplayObject):void | |
{ | |
if(!asset) | |
// oh shit... | |
else | |
// do stuff as required | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment