Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
package com.meekgeek.model{ import flash.utils.Dictionary; import org.puremvc.interfaces.IProxy; import org.puremvc.patterns.proxy.Proxy; import com.meekgeek.ApplicationFacade; public class StartupMonitorProxy extends Proxy implements IProxy { public static const NAME:String = "StartupMonitorProxy"; private var resourceList:Dictionary; public function StartupMonitorProxy(proxyName:String=null, data:Object=null) { super(proxyName, data); resourceList = new Dictionary(); } override public function getProxyName():String { return StartupMonitorProxy.NAME; } public function addResource(name:String):void { resourceList[name] = false; } public function loadResources():void { trace('loading resources'); for(var key:String in resourceList) { trace('load resource: '+key); var proxy:* = facade.retrieveProxy( key ) as Proxy; proxy.load(); } } public function resourceComplete( name:String ):void { resourceList[name] = true; checkResources(); } private function checkResources():void { var resourcesLoaded:Boolean = true; for(var key:String in resourceList) { if(!resourceList[key]) { resourcesLoaded = false; break; } } if(resourcesLoaded)this.sendNotification( ApplicationFacade.LOADING_COMPLETE); } }}
Yeah, I see that, but in the code, ApplicationFacade calls ApplicationStartupCommand which add two sub commands, ModelPrepCommand and ViewPrepCommand. I can't find where StartupMonitorCommand is used. Am I downloading a different zip?Sorry if I'm missing something right in front of my face. I'm new to this framework. Heard this was better than cairngorm
I just created this...I thought this might be a little more reusable then counting. If someone can advise if it's complying to best practice I'd like to contribute something to this post. ......It's the first proxy to be registered. All other proxies that need to be loaded before moving on, will call addResource() which adds them to a list of resources. Once all proxies have been added, you execute a command to call loadResources() which calls load() on all proxies in the list. Once the individual proxies complete the load process, they call resourceComplete() to advise StartupMonitorProxy that something has finished loading. It then checks to see if all proxies are ready. If all proxies check out, it notifies the framework to move on If this is looking like something that other's can use I can upload the files I'm using.
I just created this...I thought this might be a little more reusable then counting. If someone can advise if it's complying to best practice I'd like to contribute something to this post. It's the first proxy to be registered. All other proxies that need to be loaded before moving on, will call addResource() which adds them to a list of resources. Once all proxies have been added, you execute a command to call loadResources() which calls load() on all proxies in the list. Once the individual proxies complete the load process, they call resourceComplete() to advise StartupMonitorProxy that something has finished loading. It then checks to see if all proxies are ready. If all proxies check out, it notifies the framework to move on If this is looking like something that other's can use I can upload the files I'm using.
package com...model{ /* * From original code of Daniele Ugoletti and Meekgeek * on the puremvc forums, modified to use 'requires' instead * of blocking boolean. Also have a multi-valued status instead * of a 'loaded' boolean. * * @author Philip Sexton * @since 11.01.2008 */ public class StartupResource { private static const EMPTY :int = 1; private static const LOADING :int = 2; private static const LOADED :int = 3; public var proxyName:String; private var status :int; // StartupResources, pre-requisites for this resource, if any. // These pre-requisites must be loaded before this resource can be loaded. private var _requires :Array; public function StartupResource( proxyName:String ) { this.proxyName = proxyName; this.status = EMPTY; this.requires = new Array(); } public function setStatusToLoading() :void { status = LOADING; } public function setStatusToLoaded() :void { status = LOADED; } public function isLoaded() :Boolean { return status == LOADED; } public function set requires( resources :Array ) :void { _requires = resources; } public function get requires() :Array { return _requires; } public function isOkToLoad() :Boolean { if ( status != EMPTY ) return false; for( var i:int =0; i < requires.length; i++) { if ( ! (requires[i] as StartupResource).isLoaded() ) return false; } return true; } }}
package com...model{ import org.puremvc.interfaces.*; import org.puremvc.patterns.proxy.Proxy; import com...model.StartupResource; /* * A proxy for the startup loading process. * From original code of Daniele Ugoletti and Meekgeek * on the puremvc forums, modified to use a StartupResource * designed to cater for more complex constraints. * * @author Philip Sexton * @since 11.01.2008 */ public class StartupMonitorProxy extends Proxy implements IProxy { public static const NAME:String = "StartupMonitorProxy"; // array listing all the resources to be loaded private var resourceList:Array; //---- total resource to read //-----private var totalResources:int = 0; // number of loaded resources private var loadedResources:int = 0; public function StartupMonitorProxy ( data:Object = null ) { super ( NAME, data ); this.resourceList = new Array(); } /** * Add a resource to be loaded */ public function addResource( r :StartupResource ):void { this.resourceList.push( r ); } /** * Start/Continue to load all resources */ public function loadResources():void { for( var i:int = 0; i < this.resourceList.length; i++) { var r:StartupResource = this.resourceList[i] as StartupResource; if ( r.isOkToLoad() ) { var proxy:* = facade.retrieveProxy( r.proxyName ) as Proxy; r.setStatusToLoading(); proxy.load(); } } } /** * The resource is loaded, update the state and check if the loading process is completed * * @param name proxy name */ public function resourceLoaded( proxyName :String ):void { for( var i:int = 0; i < this.resourceList.length; i++) { var r:StartupResource = this.resourceList[i] as StartupResource; if ( r.proxyName == proxyName ) { r.setStatusToLoaded(); this.loadedResources++; // send the notification for update the progress bar //this.sendNotification( ApplicationFacade.LOADING_STEP, this.resourceList.length / this.loadedReources * 100 ); // if not all loaded, continue load. if ( !allResourcesLoaded() ) { this.loadResources(); } break; } } } /** * Check if the loading process is completed * * @return boolean process is completed */ private function allResourcesLoaded():Boolean { for( var i:int = 0; i < this.resourceList.length; i++) { var r:StartupResource = this.resourceList[i] as StartupResource; if ( !r.isLoaded() ) { return false; } } //this.sendNotification( ApplicationFacade.LOADING_COMPLETE ); return true; } }}
public class StartupCommand extends SimpleCommand implements ICommand { private var monitor :StartupMonitorProxy; override public function execute( note:INotification ) : void { facade.registerProxy( new StartupMonitorProxy() ); this.monitor = facade.retrieveProxy( StartupMonitorProxy.NAME ) as StartupMonitorProxy; ... register other proxies ... var rA :StartupResource = makeAndRegisterStartupResource( ProxyA.NAME ); var rB :StartupResource = makeAndRegisterStartupResource( ProxyB.NAME ); var rC :StartupResource = makeAndRegisterStartupResource( ProxyC.NAME ); var rD :StartupResource = makeAndRegisterStartupResource( ProxyD.NAME ); var rE :StartupResource = makeAndRegisterStartupResource( ProxyE.NAME ); var rF :StartupResource = makeAndRegisterStartupResource( ProxyF.NAME ); var rG :StartupResource = makeAndRegisterStartupResource( ProxyG.NAME ); var rH :StartupResource = makeAndRegisterStartupResource( ProxyH.NAME ); rC.requires = [ rA, rB ]; rD.requires = [ rC ]; rE.requires = [ rD ]; rH.requires = [ rE, rF, rG ]; monitor.loadResources(); ... register mediator(s) ... } private function makeAndRegisterStartupResource( proxyName :String ) :StartupResource { var r :StartupResource = new StartupResource( proxyName ); monitor.addResource( r ); return r; } }
public class StartupResourceLoadedCommand extends SimpleCommand { /** * Inform the startup monitor that a resource is now loaded. * The notification body identifies the particular resource. */ override public function execute( note:INotification ) : void { ( facade.retrieveProxy( StartupMonitorProxy.NAME ) as StartupMonitorProxy). resourceLoaded( note.getBody() as String ); } }