Cairngorm Model Locator


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /** *******************************************************************
  2. * MySnippets
  3. * Free for use
  4. *
  5. * @author Jonnie Spratley
  6. * @contact [email protected]
  7. ******************************************************************* */
  8. package
  9. {
  10. import com.adobe.cairngorm.model.IModelLocator;
  11.  
  12. import mx.collections.ArrayCollection;
  13.  
  14. /**
  15. * The Model Locator pattern is a singleton and was created purely
  16. * to be used with Flex/Air application development. In this case,
  17. * a singleton is a design pattern that allows for only one
  18. * instance of the Model Locator to be present within your a
  19. * application's memory. Any data that you think is required to live
  20. * in the application's state should be stored inside the Model Locator.
  21. * The Model Locator creates a central area where all the states
  22. * can be held in your Flex/Air application. This allows the view
  23. * components to bind to the model or state of the application
  24. * and keep everything up to date.
  25. *
  26. */
  27.  
  28. [Bindable]
  29. public final class ModelLocator implements IModelLocator
  30. {
  31. /**
  32. * Defines the Singleton instance of the Application ModelLocator
  33. */
  34. private static var instance:ModelLocator;
  35.  
  36. public function ModelLocator()
  37. {
  38. if( instance != null ) throw new Error( "Error: Singletons can only be instantiated via getInstance() method!" );
  39.  
  40. ModelLocator.instance = this;
  41. }
  42.  
  43. /**
  44. * Returns the Singleton instance of the Application ModelLocator
  45. */
  46. public static function getInstance():ModelLocator
  47. {
  48. if( instance == null ) instance = new ModelLocator();
  49.  
  50. return instance;
  51. }
  52.  
  53. // *********** Public Variables that our views are going to bind to ************** \
  54.  
  55.  
  56. // ***************** Public Static Variables for Work View States ************* \
  57. public var workflowState:uint = 0;
  58. public static const LOGIN_SCREEN:uint = 0;
  59. public static const WELCOME_SCREEN:uint = 1;
  60. }
  61. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.