MAY THE SOURCE BE WITH YOU…

Below I illustrate  how I have been able to successfully load external assets (swfs) and data into pureMVC with a sequence diagram.

Actually you should probably just download the Diagram jpg to take a closer look …

http://www.imanit.com/blog/wp-content/2008/09/Sequence.jpg

PureMVC Loading Sequence Diagram

Also Below is all the text from the diagram in case you want to cut and paste:
entry point class:
//The entry point class extends Sprite.  This sprite in most instances is the stage.
// call facade.startup and send it a reference that can be casted to the application
facade.startup(this)

ApplicationFacade.as,  override protected function initializeController( ) : void
super.initializeController();
//When startup dispatched, call preloaderCommand
// The preloaderCommand loads up the preloader asset
// Once the preloader asset the PRELOADER_LOADED is dispatched and the loaded asset is registers the

//with PreloaderMediator
// PreloaderMediator listens for Loading Nodifications and updates accordinly.
registerCommand( STARTUP, PreloaderCommand );
// once preloader loaded, run ModelPrepCommand
registerCommand( PRELOADER_LOADED, ModelPrepCommand );
// Once Model Loaded, Load the View.
registerCommand(MODEL_LOADING_COMPLETE, ViewPrepCommand);

ApplicationFacade.as, public function startup( app:Sprite ):void

//sends the “STARTUP” notification which initiates the “ApplicationStartupCommand” with a refrence to

//the application
sendNotification( STARTUP, app );

ModelPrepCommand.as,  override public function execute( note:INotification ) :void
facade.registerProxy(new StartupMonitorProxy());
// register all of your proxies as well
// these proxies are responsible for loading data.  lets look at one example called ConfigProxy
facade.registerProxy(new ConfigProxy());
// you should be able to get startupMonitorProxy code from a pureMVC demo
var startupMonitorProxy:StartupMonitorProxy = facade.retrieveProxy( StartupMonitorProxy.NAME ) as

StartupMonitorProxy;
startupMonitorProxy.app =note.getBody();
startupMonitorProxy.loadResources();

ConfigProxy.as, public function ConfigProxy ( data:Object = null )
super ( NAME, data );
startupMonitorProxy = facade.retrieveProxy( StartupMonitorProxy.NAME ) as StartupMonitorProxy;
// add the resource to load
startupMonitorProxy.addResource( ConfigProxy.NAME, true );
this.data = new ConfigVOCollection();

ConfigPorxy.as,public function load():void
// LoadEXDelegate uses the responder pattern so we need to define a result and a fault
// that are called from LoadEXDelegate accordingly
var delegateR: LoadEXDelegate = new LoadEXDelegate(this, “data/Config.xml”);
delegateR.load();

ConfigPorxy.as, public function result( rpcObject :Object ) : void
data = ConfigResource.parse(rpcObject);
this.startupMonitorProxy.resourceComplete( ConfigProxy.NAME );

ConfigPorxy.as, public function fault( info:Object ) : void
// this is called when the delegate receives a fault from the service
this.sendNotification( ApplicationFacade.LOAD_FAILED, ApplicationFacade.ERROR_LOAD_FILE );

ViewPrepCommand.as,  override public function execute( note:INotification ) :void
// Register the ApplicationMediator
// Notice we are sending the stage to the application mediator.
facade.registerMediator( new ApplicationMediator( note.getBody() as Sprite ) );

ApplicationMediator.as,  public function ApplicationMediator( viewComponent:Sprite )
super( NAME, viewComponent );
loader = LoadManager.getInstance();
loader.load(loader.ASSET,”assets/A.swf”,1,onALoadComplete,onLoadFail);
loader.load(loader.ASSET,”assets/B.swf”,1,onBLoadComplete,onLoadFail);

LoadManager.as, public static function getInstance() : LoadManager
if (instance == null)
{
//Its very important we keep a memory reference to everything we load or
// The garbage collector could kill it while we are waiting for the loadcomplete callback
aLAR = new Array();
instance = new LoadManager( );
}
return instance
;

LoadManager.as, public function load(loadType:String, url:String, priority:uint, onLC:Function,onLF:Function): void
switch ( loadType )
{

case ASSET:
// define url, an onComplete function, and an onFail function.
aLAR.push(new AssetLoader(url, onLC, onLF ));
//When the complete or Fail comes back call the AssetLoader kill function for that AL to clean

//up memory.
break;
}

ApplicationMediator.as, protected function onALoadComplete(e:Event):void
app.A = e.target.content;
show(app.A  as DisplayObject,2);
facade.registerMediator( new PanelMediator( app.panel) );
oneLoaded();

ApplicationMediator.as, private function show(myDO:DisplayObject,layer:uint, initAlpha:Number =0):void
//show takes care of layering and visibility.  uses a private varaible called orderAr
var ind: uint = 0;
for (var cntx:uint= 0; cntx < orderAr.length; cntx++)
{
if (layer > orderAr[cntx]) ind++;
}
orderAr.push (layer);
trace (myDO + ” beats: ” + ind + ” with a score of:”  + layer + ” in array:”  + orderAr);
app.addChildAt(myDO, ind)
myDO.visible= true;
myDO.x = 0;
myDO.y =0;
myDO.alpha=initAlpha;

ApplicationMediator.as, private function oneLoaded():void
loaded++;
if (loaded == 2)
{
sendNotification( ApplicationFacade.LOADING_COMPLETE);
}

Comments are closed.

Proudly powered by WordPress. Theme developed with WordPress Theme Generator.
Copyright © MAY THE SOURCE BE WITH YOU…. All rights reserved.