PageRenderTime 65ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/bin-debug/srcview/source/org/osflash/signals/natives/sets/NativeSignalSet.as.html

https://bitbucket.org/tshubbard/zfstarlingtutorial
HTML | 122 lines | 104 code | 17 blank | 1 comment | 0 complexity | 85eb6647d8e456cca792a21d0fe64ae3 MD5 | raw file
  1. <!-- saved from url=(0014)about:internet -->
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6. <title>NativeSignalSet.as</title>
  7. <link rel="stylesheet" type="text/css" href="../../../../../../SourceStyles.css"/>
  8. </head>
  9. <body><pre><span class="ActionScriptpackage">package</span> <span class="ActionScriptDefault_Text">org</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">osflash</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">signals</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">natives</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">sets</span>
  10. <span class="ActionScriptBracket/Brace">{</span>
  11. <span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">org</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">osflash</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">signals</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">natives</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">INativeDispatcher</span>;
  12. <span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">org</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">osflash</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">signals</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">natives</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">NativeSignal</span>;
  13. <span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">events</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">Event</span>;
  14. <span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">events</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">IEventDispatcher</span>;
  15. <span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">utils</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">Dictionary</span>;
  16. <span class="ActionScriptASDoc">/**
  17. * A convenient way to access a logical set of signals.
  18. *
  19. * @author Jon Adams
  20. *
  21. * @example SignalSets allow you to get predefined signals for many built in events
  22. * &lt;listing version="3.0" &gt;
  23. package {
  24. import org.osflash.signals.natives.sets.InteractiveObjectSignalSet;
  25. import flash.display.Sprite;
  26. import flash.events.Event;
  27. public class Example extends Sprite {
  28. private var button:Sprite;
  29. private var buttonSignals:InteractiveObjectSignalSet;
  30. public function Main() {
  31. button = new Sprite();
  32. button.graphics.beginFill(0xff0000);
  33. button.graphics.drawRect(0, 0, 100, 100);
  34. button.graphics.endFill();
  35. buttonSignals = new InteractiveObjectSignalSet(button);
  36. buttonSignals.click.add(handler);
  37. buttonSignals.addedToStage.add(handler);
  38. buttonSignals.enterFrame.addOnce(handler);
  39. addChild(button);
  40. }
  41. private function handler(event:Event):void {
  42. trace(event.target, "fired", event.type);
  43. }
  44. }
  45. }
  46. * &lt;/listing&gt;
  47. */</span>
  48. <span class="ActionScriptReserved">public</span> <span class="ActionScriptclass">class</span> <span class="ActionScriptDefault_Text">NativeSignalSet</span>
  49. <span class="ActionScriptBracket/Brace">{</span>
  50. <span class="ActionScriptReserved">protected</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">target</span>:<span class="ActionScriptDefault_Text">IEventDispatcher</span>;
  51. <span class="ActionScriptReserved">protected</span> <span class="ActionScriptReserved">const</span> <span class="ActionScriptDefault_Text">_signals</span>:<span class="ActionScriptDefault_Text">Dictionary</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Dictionary</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptBracket/Brace">)</span>;
  52. <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">NativeSignalSet</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">target</span>:<span class="ActionScriptDefault_Text">IEventDispatcher</span><span class="ActionScriptBracket/Brace">)</span>
  53. <span class="ActionScriptBracket/Brace">{</span>
  54. <span class="ActionScriptReserved">this</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">target</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">target</span>;
  55. <span class="ActionScriptBracket/Brace">}</span>
  56. <span class="ActionScriptASDoc">/**
  57. * Lazily instantiates a NativeSignal
  58. * @throws ArgumentError &lt;code&gt;ArgumentError&lt;/code&gt;: eventType must not be null.
  59. */</span>
  60. <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">getNativeSignal</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">eventType</span>:<span class="ActionScriptDefault_Text">String</span><span class="ActionScriptOperator">,</span> <span class="ActionScriptDefault_Text">eventClass</span>:<span class="ActionScriptDefault_Text">Class</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">null</span><span class="ActionScriptBracket/Brace">)</span>:<span class="ActionScriptDefault_Text">NativeSignal</span>
  61. <span class="ActionScriptBracket/Brace">{</span>
  62. <span class="ActionScriptReserved">if</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">null</span> <span class="ActionScriptOperator">==</span> <span class="ActionScriptDefault_Text">eventType</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptReserved">throw</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">ArgumentError</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptString">'eventType must not be null.'</span><span class="ActionScriptBracket/Brace">)</span>;
  63. <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">_signals</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">eventType</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">||=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">NativeSignal</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">target</span><span class="ActionScriptOperator">,</span> <span class="ActionScriptDefault_Text">eventType</span><span class="ActionScriptOperator">,</span> <span class="ActionScriptDefault_Text">eventClass</span> <span class="ActionScriptOperator">||</span> <span class="ActionScriptDefault_Text">Event</span><span class="ActionScriptBracket/Brace">)</span>;
  64. <span class="ActionScriptBracket/Brace">}</span>
  65. <span class="ActionScriptASDoc">/**
  66. * The current number of listeners for the signal.
  67. */</span>
  68. <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptReserved">get</span> <span class="ActionScriptDefault_Text">numListeners</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptBracket/Brace">)</span>:<span class="ActionScriptDefault_Text">int</span>
  69. <span class="ActionScriptBracket/Brace">{</span>
  70. <span class="ActionScriptComment">// TODO : This is horrid, it's very expensive to call this if there is a lot of signals.
  71. </span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">count</span>:<span class="ActionScriptDefault_Text">int</span> <span class="ActionScriptOperator">=</span> 0;
  72. <span class="ActionScriptReserved">for each</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">signal</span>:<span class="ActionScriptDefault_Text">INativeDispatcher</span> <span class="ActionScriptReserved">in</span> <span class="ActionScriptDefault_Text">_signals</span><span class="ActionScriptBracket/Brace">)</span>
  73. <span class="ActionScriptBracket/Brace">{</span>
  74. <span class="ActionScriptDefault_Text">count</span> <span class="ActionScriptOperator">+=</span> <span class="ActionScriptDefault_Text">signal</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">numListeners</span>;
  75. <span class="ActionScriptBracket/Brace">}</span>
  76. <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">count</span>;
  77. <span class="ActionScriptBracket/Brace">}</span>
  78. <span class="ActionScriptASDoc">/**
  79. * The signals in the SignalSet as an Array.
  80. */</span>
  81. <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptReserved">get</span> <span class="ActionScriptDefault_Text">signals</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptBracket/Brace">)</span>:<span class="ActionScriptDefault_Text">Array</span>
  82. <span class="ActionScriptBracket/Brace">{</span>
  83. <span class="ActionScriptComment">// TODO : This is horrid, it's very expensive to call this if there is a lot of signals.
  84. </span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">result</span>:<span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptBracket/Brace">]</span>;
  85. <span class="ActionScriptReserved">for each</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">signal</span>:<span class="ActionScriptDefault_Text">INativeDispatcher</span> <span class="ActionScriptReserved">in</span> <span class="ActionScriptDefault_Text">_signals</span><span class="ActionScriptBracket/Brace">)</span>
  86. <span class="ActionScriptBracket/Brace">{</span>
  87. <span class="ActionScriptDefault_Text">result</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">result</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">length</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">signal</span>;
  88. <span class="ActionScriptBracket/Brace">}</span>
  89. <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">result</span>;
  90. <span class="ActionScriptBracket/Brace">}</span>
  91. <span class="ActionScriptASDoc">/**
  92. * Unsubscribes all listeners from all signals in the set.
  93. */</span>
  94. <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">removeAll</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptBracket/Brace">)</span>:<span class="ActionScriptReserved">void</span>
  95. <span class="ActionScriptBracket/Brace">{</span>
  96. <span class="ActionScriptReserved">for each</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">signal</span>:<span class="ActionScriptDefault_Text">INativeDispatcher</span> <span class="ActionScriptReserved">in</span> <span class="ActionScriptDefault_Text">_signals</span><span class="ActionScriptBracket/Brace">)</span>
  97. <span class="ActionScriptBracket/Brace">{</span>
  98. <span class="ActionScriptDefault_Text">signal</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">removeAll</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptBracket/Brace">)</span>;
  99. <span class="ActionScriptReserved">delete</span> <span class="ActionScriptDefault_Text">_signals</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">signal</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">eventType</span><span class="ActionScriptBracket/Brace">]</span>;
  100. <span class="ActionScriptBracket/Brace">}</span>
  101. <span class="ActionScriptBracket/Brace">}</span>
  102. <span class="ActionScriptBracket/Brace">}</span>
  103. <span class="ActionScriptBracket/Brace">}</span>
  104. </pre></body>
  105. </html>