/src/org/robotlegs/mvcs/Actor.as

https://bitbucket.org/HopeSky/mars_nd2d · ActionScript · 102 lines · 34 code · 12 blank · 56 comment · 2 complexity · 0eb26af985e5a900e4356376e83ba4b7 MD5 · raw file

  1. /*
  2. * Copyright (c) 2009 the original author or authors
  3. *
  4. * Permission is hereby granted to use, modify, and distribute this file
  5. * in accordance with the terms of the license agreement accompanying it.
  6. */
  7. package org.robotlegs.mvcs
  8. {
  9. import flash.events.Event;
  10. import flash.events.IEventDispatcher;
  11. import org.robotlegs.base.EventMap;
  12. import org.robotlegs.core.IEventMap;
  13. /**
  14. * Abstract MVCS <code>IActor</code> implementation
  15. *
  16. * <p>As part of the MVCS implementation the <code>Actor</code> provides core functionality to an applications
  17. * various working parts.</p>
  18. *
  19. * <p>Some possible uses for the <code>Actor</code> include, but are no means limited to:</p>
  20. *
  21. * <ul>
  22. * <li>Service classes</li>
  23. * <li>Model classes</li>
  24. * <li>Controller classes</li>
  25. * <li>Presentation model classes</li>
  26. * </ul>
  27. *
  28. * <p>Essentially any class where it might be advantagous to have basic dependency injection supplied is a candidate
  29. * for extending <code>Actor</code>.</p>
  30. *
  31. */
  32. public class Actor
  33. {
  34. /**
  35. * @private
  36. */
  37. protected var _eventDispatcher:IEventDispatcher;
  38. /**
  39. * @private
  40. */
  41. protected var _eventMap:IEventMap;
  42. //---------------------------------------------------------------------
  43. // Constructor
  44. //---------------------------------------------------------------------
  45. public function Actor()
  46. {
  47. }
  48. //---------------------------------------------------------------------
  49. // API
  50. //---------------------------------------------------------------------
  51. /**
  52. * @inheritDoc
  53. */
  54. public function get eventDispatcher():IEventDispatcher
  55. {
  56. return _eventDispatcher;
  57. }
  58. [Inject]
  59. /**
  60. * @private
  61. */
  62. public function set eventDispatcher(value:IEventDispatcher):void
  63. {
  64. _eventDispatcher = value;
  65. }
  66. //---------------------------------------------------------------------
  67. // Internal
  68. //---------------------------------------------------------------------
  69. /**
  70. * Local EventMap
  71. *
  72. * @return The EventMap for this Actor
  73. */
  74. protected function get eventMap():IEventMap
  75. {
  76. return _eventMap || (_eventMap = new EventMap(eventDispatcher));
  77. }
  78. /**
  79. * Dispatch helper method
  80. *
  81. * @param event The <code>Event</code> to dispatch on the <code>IContext</code>'s <code>IEventDispatcher</code>
  82. */
  83. protected function dispatch(event:Event):Boolean
  84. {
  85. if(eventDispatcher.hasEventListener(event.type))
  86. return eventDispatcher.dispatchEvent(event);
  87. return false;
  88. }
  89. }
  90. }