Skip to content

Instantly share code, notes, and snippets.

@creynders
Created September 19, 2011 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creynders/b701af627d7be558e435 to your computer and use it in GitHub Desktop.
Save creynders/b701af627d7be558e435 to your computer and use it in GitHub Desktop.
Benefits of custom signal with AssetLoader
/* 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