Posted By

maxkar on 01/04/09


Tagged

Flex as3 cairngorm flamingo granite


Versions (?)

Cairngorm Flamingo Granite Command Example


 / Published in: ActionScript 3
 

  1. /*
  2.   This command class is run when the Controller intercepts a
  3.   Event. Typically, the same Command can handle
  4.   many events, and figure out how to handle them in the execute method.
  5.   For now, this guy merely calls the Delegate's method,
  6.   and when the data comes back, he updates the ModelLocator.
  7.  
  8.   Commands should ALWAYS be the ones setting ModelLocator. View's shouldn't,
  9.   nor should Delegate's. There are times when it's ok for a View to do so,
  10.   but you should be sure you couldn't do it in a Command instead. View's
  11.   should technically be "asking" the Controller via Events to change data.
  12.   ...yes, I know, this is a LOT of events.
  13. */
  14. package com.xx.command
  15. {
  16. import com.adobe.cairngorm.commands.ICommand;
  17. import com.adobe.cairngorm.control.CairngormEvent;
  18. import com.xx.business.UserDelegate;
  19. import com.xx.event.LoginEvent;
  20. import com.xx.event.MainMenuEvent;
  21. import com.xx.model.DirectModelLocator;
  22. import com.xx.model.StateManager;
  23. import com.xx.util.ErrorHandling;
  24.  
  25. import mx.controls.Alert;
  26. import mx.rpc.IResponder;
  27. //import mx.rpc.events.FaultEvent;
  28. import org.granite.tide.events.TideResultEvent;
  29. import org.granite.tide.events.TideFaultEvent;
  30.  
  31. public class LoginCommand implements ICommand, IResponder
  32. {
  33. public function LoginCommand():void {}
  34.  
  35. private var model : DirectModelLocator = DirectModelLocator.getInstance();
  36.  
  37. public function execute(event : CairngormEvent) : void
  38. {
  39. var delegate : UserDelegate = new UserDelegate( this );
  40. var loginEvent : LoginEvent = LoginEvent( event );
  41.  
  42. delegate.loginPrincipal( loginEvent.user );
  43. }
  44.  
  45. public function result(data : Object) : void
  46. {
  47. model.isLoggedIn = data.result;
  48.  
  49. if ( model.isLoggedIn )
  50. {
  51. //Update server binding
  52. // model.serverBindings.loggedInPrincipal.update();
  53. new MainMenuEvent().dispatch();
  54. model.stateManager.setState(StateManager.APPLICATION_MAIN_VIEW);
  55. }
  56. else
  57. {
  58. if(model.stateManager.appViewState == StateManager.APPLICATION_LOGIN_VIEW)
  59. {
  60. Alert.show( "User or Password is invalid", "Login failed!" );
  61. }
  62. else
  63. {
  64. model.stateManager.setState(StateManager.APPLICATION_LOGIN_VIEW);
  65. }
  66. }
  67. }
  68.  
  69. public function fault(info : Object) : void
  70. {
  71. var faultEvent : TideFaultEvent = TideFaultEvent( info );
  72. ErrorHandling.tideFault( faultEvent, "Error", "An error occured: " );
  73. }
  74.  
  75. }
  76. }

Report this snippet  

You need to login to post a comment.