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