-
-
Save creynders/b701af627d7be558e435 to your computer and use it in GitHub Desktop.
Benefits of custom signal with AssetLoader
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
/* EXAMPLE OF THE BENEFITS OF HAVING A CUSTOM SIGNAL DISPATCHED BY ASSETLOADER */ | |
//IConfigDataRetrieverService | |
function retrieveConfigData():void; | |
//XMLLoaderConfigDataRetrieverService | |
private var _loader : XMLLoader; | |
[Inject] | |
public var dataRetrievedSignal : ConfigDataRetrievedSignal | |
public function retrieveConfigData() : void{ | |
var request : URLRequest = new URLRequest( 'config.xml' ); | |
_loader = new XMLLoader( request ) | |
_loader.responder.successSignal = dataRetrievedSignal; | |
} | |
//RetrieveConfigDataCommand | |
[Inject] | |
public var configDataRetrieverService : IConfigDataRetrieverService | |
public function execute() : void{ | |
service.retrieveConfigData(); | |
} | |
//ConfigDataRetrievedCommand, mapped to ConfigDataRetrievedSignal | |
[Inject] | |
public var configDataXML : XML | |
public function execute() : void{ | |
//do stuff with xml | |
} | |
//-------------- | |
//now let's say that we decide to use embedded xml data for testing purpose or whatever | |
//------------- | |
//EmbeddedConfigDataRetrieverService | |
[Inject] | |
public var dataRetrievedSignal : ConfigDataRetrievedSignal; | |
public function retrieveConfigData() : void{ | |
dataRetrievedSignal.dispatch( ConfigDataConstants.CONFIG_XML ); | |
} | |
//All we need to do is change the mapping of IConfigDataRetrieverService from | |
//XMLLoaderConfigDataRetrieverService to EmbeddedConfigDataRetrieverService | |
//and it works just as before, since there's no direct dependency on AssetLoader or IAssetLoader |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment