PageRenderTime 36ms CodeModel.GetById 28ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/src/org/osflash/signals/Signal.as

http://github.com/robertpenner/as3-signals
ActionScript | 51 lines | 16 code | 4 blank | 31 comment | 2 complexity | f342ac5e077569ef84856b6a692731c9 MD5 | raw file
 1package org.osflash.signals
 2{
 3
 4	/** 
 5	 * Allows the valueClasses to be set in MXML, e.g.
 6	 * <signals:Signal id="nameChanged">{[String, uint]}</signals:Signal>
 7	 */
 8	[DefaultProperty("valueClasses")]	
 9	
10	/**
11	 * Signal dispatches events to multiple listeners.
12	 * It is inspired by C# events and delegates, and by
13	 * <a target="_top" href="http://en.wikipedia.org/wiki/Signals_and_slots">signals and slots</a>
14	 * in Qt.
15	 * A Signal adds event dispatching functionality through composition and interfaces,
16	 * rather than inheriting from a dispatcher.
17	 * <br/><br/>
18	 * Project home: <a target="_top" href="http://github.com/robertpenner/as3-signals/">http://github.com/robertpenner/as3-signals/</a>
19	 */
20	public class Signal extends OnceSignal implements ISignal
21	{
22		/**
23		 * Creates a Signal instance to dispatch value objects.
24		 * @param	valueClasses Any number of class references that enable type checks in dispatch().
25		 * For example, new Signal(String, uint)
26		 * would allow: signal.dispatch("the Answer", 42)
27		 * but not: signal.dispatch(true, 42.5)
28		 * nor: signal.dispatch()
29		 *
30		 * NOTE: In AS3, subclasses cannot call super.apply(null, valueClasses),
31		 * but this constructor has logic to support super(valueClasses).
32		 */
33		public function Signal(...valueClasses)
34		{
35			// Cannot use super.apply(null, valueClasses), so allow the subclass to call super(valueClasses).
36			valueClasses = (valueClasses.length == 1 && valueClasses[0] is Array) ? valueClasses[0]:valueClasses;
37			
38			super(valueClasses);
39		}
40		
41		/**
42		 * @inheritDoc
43		 * @throws flash.errors.IllegalOperationError <code>IllegalOperationError</code>: You cannot addOnce() then add() the same listener without removing the relationship first.
44		 * @throws ArgumentError <code>ArgumentError</code>: Given listener is <code>null</code>.
45		 */
46		public function add(listener:Function):ISlot
47		{
48			return registerListener(listener);
49		}
50	}
51}