puremvc
|
|
« Reply #1 on: November 11, 2011, 08:01:22 » |
|
Unless you have very special application needs, you should register all your commands at once. There are a couple of places you can do this.
1) ApplicationFacade.initializeController()
If you do them here be sure to call super.initializeController first...
package com.me.myapp { import com.me.myapp.controller.command.StartupCommand; import com.me.myapp.controller.command.ThisCommand ; import com.me.myapp.controller.command.ThatCommand ; import com.me.myapp.controller.command.TheOtherCommand ; import com.me.myapp.controller.constant.AppConstants; import org.puremvc.as3.patterns.facade.Facade; public class ApplicationFacade extends Facade {
/** * The singleton instance factory method. */ public static function getInstance( ) : ApplicationFacade { if ( instance == null ) instance = new ApplicationFacade( ); return instance as ApplicationFacade; } override protected function initializeController():void { super.initializeController(); registerCommand( AppConstants.STARTUP, StartupCommand ); registerCommand( AppConstants.THIS, ThisCommand ); registerCommand( AppConstants.THAT, ThatCommand ); registerCommand( AppConstants.THE_OTHER, TheOtherCommand ); }
/** * A convenience method for starting up the PureMVC * apparatus from the application. */ public function startup( app:MyApp ):void { registerCommand( AppConstants.STARTUP, StartupCommand ); sendNotification( AppConstants.STARTUP, app ); } } }
2) In your StartupCommand, *before* registering Proxies and Mediators.
Of course your StartupCommand itself will need to be registered in the ApplicationFacade, or it could never be triggered. But you can now move it down into the startup convenience method just before sending the STARTUP note.
package com.me.myapp { import com.me.myapp.controller.command.StartupCommand; import com.me.myapp.controller.constant.AppConstants; import org.puremvc.as3.patterns.facade.Facade; public class ApplicationFacade extends Facade {
/** * The singleton instance factory method. */ public static function getInstance( ) : ApplicationFacade { if ( instance == null ) instance = new ApplicationFacade( ); return instance as ApplicationFacade; } /** * A convenience method for starting up the PureMVC * apparatus from the application. */ public function startup( app:MyApp ):void { registerCommand( AppConstants.STARTUP, StartupCommand ); sendNotification( AppConstants.STARTUP, app ); } } } package com.me.myapp.command { import com.me.myapp.controller.command.ThisCommand ; import com.me.myapp.controller.command.ThatCommand ; import com.me.myapp.controller.command.TheOtherCommand ; import com.me.myapp.controller.constant.AppConstants;
import com.me.myapp.controller.model.proxy.SomeProxy; import com.me.myapp.controller.model.proxy.AProxy;
import com.me.myapp.controller.view.mediator.ApplicationMediator; import org.puremvc.as3.interfaces.INotification; import org.puremvc.as3.patterns.command.SimpleCommand;
public class StartupCommand extends SimpleCommand { override public function execute(note:INotification):void { // Prepare the Controller facade.registerCommand( AppConstants.STARTUP, StartupCommand ); facade.registerCommand( AppConstants.THIS, ThisCommand ); facade.registerCommand( AppConstants.THAT, ThatCommand ); facade.registerCommand( AppConstants.THE_OTHER, TheOtherCommand );
// Prepare the Model facade.registerProxy( new SomeProxy() ); facade.registerProxy( new AProxy() ); // Prepare the View var app:MyApp= note.getBody() as MyApp; facade.registerMediator( new ApplicationMediator( app ) );
} } } -=Cliff>
|