PageRenderTime 88ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/doc/generated/SoundManager2_AS3.html

https://gitlab.com/gregtyka/SoundManager2
HTML | 1013 lines | 739 code | 274 blank | 0 comment | 0 complexity | 267291e10f8b2e849c61b3211040e11f MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>SoundManager2_AS3.as</title>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  7. <link rel="stylesheet" media="all" href="docco.css" />
  8. </head>
  9. <body>
  10. <div id="container">
  11. <div id="background"></div>
  12. <ul id="jump_to">
  13. <li>
  14. <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
  15. <a class="small" href="javascript:void(0);">+</a>
  16. <div id="jump_wrapper">
  17. <div id="jump_page">
  18. <a class="source" href="soundmanager2.html">
  19. soundmanager2.js
  20. </a>
  21. <a class="source" href="SoundManager2_AS.html">
  22. SoundManager2_AS.as
  23. </a>
  24. <a class="source" href="SoundManager2_AS3.html">
  25. SoundManager2_AS3.as
  26. </a>
  27. <a class="source" href="SoundManager2_SMSound_AS3.html">
  28. SoundManager2_SMSound_AS3.as
  29. </a>
  30. </div>
  31. </li>
  32. </ul>
  33. <ul class="sections">
  34. <li id="title">
  35. <div class="annotation">
  36. <h1>SoundManager2_AS3.as</h1>
  37. </div>
  38. </li>
  39. <li id="section-1">
  40. <div class="annotation">
  41. <div class="pilwrap ">
  42. <a class="pilcrow" href="#section-1">&#182;</a>
  43. </div>
  44. </div>
  45. <div class="content"><div class='highlight'><pre><span class="comment">/**
  46. * SoundManager 2: Javascript Sound for the Web
  47. * ----------------------------------------------
  48. * http://schillmania.com/projects/soundmanager2/
  49. *
  50. * Copyright (c) 2007, Scott Schiller. All rights reserved.
  51. * Code licensed under the BSD License:
  52. * http://www.schillmania.com/projects/soundmanager2/license.txt
  53. *
  54. * Flash 9 / ActionScript 3 version
  55. */</span>
  56. <span class="package"><span class="keyword">package</span> {</span>
  57. <span class="preprocessor"><span class="keyword">import</span> flash.display.Sprite;</span>
  58. <span class="preprocessor"><span class="keyword">import</span> flash.events.Event;</span>
  59. <span class="preprocessor"><span class="keyword">import</span> flash.events.IOErrorEvent;</span>
  60. <span class="preprocessor"><span class="keyword">import</span> flash.events.MouseEvent;</span>
  61. <span class="preprocessor"><span class="keyword">import</span> flash.events.SecurityErrorEvent;</span>
  62. <span class="preprocessor"><span class="keyword">import</span> flash.events.AsyncErrorEvent;</span>
  63. <span class="preprocessor"><span class="keyword">import</span> flash.events.NetStatusEvent;</span>
  64. <span class="preprocessor"><span class="keyword">import</span> flash.events.TimerEvent;</span>
  65. <span class="preprocessor"><span class="keyword">import</span> flash.external.ExternalInterface;</span> <span class="comment">// woo</span>
  66. <span class="preprocessor"><span class="keyword">import</span> flash.media.Sound;</span>
  67. <span class="preprocessor"><span class="keyword">import</span> flash.media.SoundChannel;</span>
  68. <span class="preprocessor"><span class="keyword">import</span> flash.media.SoundMixer;</span>
  69. <span class="preprocessor"><span class="keyword">import</span> flash.net.URLLoader;</span>
  70. <span class="preprocessor"><span class="keyword">import</span> flash.net.URLRequest;</span>
  71. <span class="preprocessor"><span class="keyword">import</span> flash.system.Security;</span>
  72. <span class="preprocessor"><span class="keyword">import</span> flash.system.System;</span>
  73. <span class="preprocessor"><span class="keyword">import</span> flash.text.TextField;</span>
  74. <span class="preprocessor"><span class="keyword">import</span> flash.text.TextFormat;</span>
  75. <span class="preprocessor"><span class="keyword">import</span> flash.text.TextFieldAutoSize;</span>
  76. <span class="preprocessor"><span class="keyword">import</span> flash.ui.ContextMenu;</span>
  77. <span class="preprocessor"><span class="keyword">import</span> flash.ui.ContextMenuItem;</span>
  78. <span class="preprocessor"><span class="keyword">import</span> flash.utils.setInterval;</span>
  79. <span class="preprocessor"><span class="keyword">import</span> flash.utils.clearInterval;</span>
  80. <span class="preprocessor"><span class="keyword">import</span> flash.utils.Dictionary;</span>
  81. <span class="preprocessor"><span class="keyword">import</span> flash.utils.Timer;</span>
  82. <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SoundManager2_AS3</span> <span class="keyword">extends</span> <span class="title">Sprite</span> {</span>
  83. <span class="keyword">public</span> <span class="keyword">var</span> version:String = <span class="string">"V2.97a.20150601"</span>;
  84. <span class="keyword">public</span> <span class="keyword">var</span> version_as:String = <span class="string">"(AS3/Flash 9)"</span>;
  85. <span class="comment">/**
  86. * Cross-domain security options
  87. * HTML on foo.com loading .swf hosted on bar.com? Define your "HTML domain" here to allow JS+Flash communication to work.
  88. * // allow_xdomain_scripting = true;
  89. * // xdomain = "foo.com";
  90. * For all domains (possible security risk?), use xdomain = "*"; which ends up as System.security.allowDomain("*");
  91. * When loading from HTTPS, use System.security.allowInsecureDomain();
  92. * See http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/system/Security.html#allowDomain()
  93. */</span>
  94. <span class="keyword">public</span> <span class="keyword">var</span> allow_xdomain_scripting:Boolean = <span class="literal">false</span>;
  95. <span class="keyword">public</span> <span class="keyword">var</span> xdomain:String = <span class="string">"*"</span>;</pre></div></div>
  96. </li>
  97. <li id="section-2">
  98. <div class="annotation">
  99. <div class="pilwrap ">
  100. <a class="pilcrow" href="#section-2">&#182;</a>
  101. </div>
  102. <p>externalInterface references (for Javascript callbacks)</p>
  103. </div>
  104. <div class="content"><div class='highlight'><pre> <span class="keyword">public</span> <span class="keyword">var</span> baseJSController:String = <span class="string">"soundManager"</span>;
  105. <span class="keyword">public</span> <span class="keyword">var</span> baseJSObject:String = baseJSController + <span class="string">".sounds"</span>;</pre></div></div>
  106. </li>
  107. <li id="section-3">
  108. <div class="annotation">
  109. <div class="pilwrap ">
  110. <a class="pilcrow" href="#section-3">&#182;</a>
  111. </div>
  112. <p>internal objects</p>
  113. </div>
  114. <div class="content"><div class='highlight'><pre> <span class="keyword">public</span> <span class="keyword">var</span> sounds:Array = []; <span class="comment">// indexed string array</span>
  115. <span class="keyword">public</span> <span class="keyword">var</span> soundObjects: Dictionary = <span class="keyword">new</span> Dictionary(); <span class="comment">// associative Sound() object Dictionary type</span>
  116. <span class="keyword">public</span> <span class="keyword">var</span> timer: Timer = <span class="literal">null</span>;
  117. <span class="keyword">public</span> <span class="keyword">var</span> pollingEnabled: Boolean = <span class="literal">false</span>; <span class="comment">// polling (timer) flag - disabled by default, enabled by JS-&gt;Flash call</span>
  118. <span class="keyword">public</span> <span class="keyword">var</span> debugEnabled: Boolean = <span class="literal">true</span>; <span class="comment">// Flash debug output enabled by default, disabled by JS call</span>
  119. <span class="keyword">public</span> <span class="keyword">var</span> flashDebugEnabled: Boolean = <span class="literal">false</span>; <span class="comment">// Flash internal debug output (write to visible SWF in browser)</span>
  120. <span class="keyword">public</span> <span class="keyword">var</span> loaded: Boolean = <span class="literal">false</span>;
  121. <span class="keyword">public</span> <span class="keyword">var</span> currentObject: SoundManager2_SMSound_AS3 = <span class="literal">null</span>;
  122. <span class="keyword">public</span> <span class="keyword">var</span> paramList:Object = <span class="literal">null</span>;
  123. <span class="keyword">public</span> <span class="keyword">var</span> messages:Array = [];
  124. <span class="keyword">public</span> <span class="keyword">var</span> textField: TextField = <span class="literal">null</span>;
  125. <span class="keyword">public</span> <span class="keyword">var</span> textStyle: TextFormat = <span class="keyword">new</span> TextFormat();
  126. <span class="keyword">public</span> <span class="keyword">var</span> didSandboxMessage: Boolean = <span class="literal">false</span>;
  127. <span class="keyword">public</span> <span class="keyword">var</span> caughtFatal: Boolean = <span class="literal">false</span>;
  128. <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">SoundManager2_AS3</span><span class="params">()</span> {</span>
  129. <span class="keyword">if</span> (allow_xdomain_scripting &amp;&amp; xdomain) {
  130. Security.allowDomain(xdomain);
  131. version_as += <span class="string">' - cross-domain enabled'</span>;
  132. }
  133. <span class="keyword">this</span>.paramList = <span class="keyword">this</span>.root.loaderInfo.parameters;</pre></div></div>
  134. </li>
  135. <li id="section-4">
  136. <div class="annotation">
  137. <div class="pilwrap ">
  138. <a class="pilcrow" href="#section-4">&#182;</a>
  139. </div>
  140. <d>
  141. </div>
  142. <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (<span class="keyword">this</span>.paramList[<span class="string">'debug'</span>] == <span class="number">1</span>) {
  143. <span class="keyword">this</span>.flashDebugEnabled = <span class="literal">true</span>;
  144. }
  145. <span class="keyword">if</span> (<span class="keyword">this</span>.flashDebugEnabled) {
  146. <span class="keyword">var</span> canvas: Sprite = <span class="keyword">new</span> Sprite();
  147. canvas.graphics.drawRect(<span class="number">0</span>, <span class="number">0</span>, stage.stageWidth, stage.stageHeight);
  148. addChild(canvas);
  149. }</pre></div></div>
  150. </li>
  151. <li id="section-5">
  152. <div class="annotation">
  153. <div class="pilwrap ">
  154. <a class="pilcrow" href="#section-5">&#182;</a>
  155. </div>
  156. <p></d></p>
  157. </div>
  158. <div class="content"><div class='highlight'><pre>
  159. flashDebug(<span class="string">'SM2 SWF '</span> + version + <span class="string">' '</span> + version_as);</pre></div></div>
  160. </li>
  161. <li id="section-6">
  162. <div class="annotation">
  163. <div class="pilwrap ">
  164. <a class="pilcrow" href="#section-6">&#182;</a>
  165. </div>
  166. <p>context menu item with version info</p>
  167. </div>
  168. <div class="content"><div class='highlight'><pre>
  169. <span class="keyword">var</span> sm2Menu:ContextMenu = <span class="keyword">new</span> ContextMenu();
  170. <span class="keyword">var</span> sm2MenuItem:ContextMenuItem = <span class="keyword">new</span> ContextMenuItem(<span class="string">'SoundManager '</span> + version + <span class="string">' '</span> + version_as);
  171. sm2MenuItem.enabled = <span class="literal">false</span>;
  172. sm2Menu.customItems.push(sm2MenuItem);
  173. contextMenu = sm2Menu;
  174. <span class="keyword">if</span> (ExternalInterface.available) {
  175. flashDebug(<span class="string">'ExternalInterface available'</span>);
  176. <span class="keyword">try</span> {
  177. flashDebug(<span class="string">'Adding ExternalInterface callbacks...'</span>);
  178. ExternalInterface.addCallback(<span class="string">'_load'</span>, _load);
  179. ExternalInterface.addCallback(<span class="string">'_unload'</span>, _unload);
  180. ExternalInterface.addCallback(<span class="string">'_stop'</span>, _stop);
  181. ExternalInterface.addCallback(<span class="string">'_start'</span>, _start);
  182. ExternalInterface.addCallback(<span class="string">'_pause'</span>, _pause);
  183. ExternalInterface.addCallback(<span class="string">'_setPosition'</span>, _setPosition);
  184. ExternalInterface.addCallback(<span class="string">'_setPan'</span>, _setPan);
  185. ExternalInterface.addCallback(<span class="string">'_setVolume'</span>, _setVolume);
  186. ExternalInterface.addCallback(<span class="string">'_setPolling'</span>, _setPolling);
  187. ExternalInterface.addCallback(<span class="string">'_externalInterfaceTest'</span>, _externalInterfaceTest);
  188. ExternalInterface.addCallback(<span class="string">'_disableDebug'</span>, _disableDebug);
  189. ExternalInterface.addCallback(<span class="string">'_getMemoryUse'</span>, _getMemoryUse);
  190. ExternalInterface.addCallback(<span class="string">'_createSound'</span>, _createSound);
  191. ExternalInterface.addCallback(<span class="string">'_destroySound'</span>, _destroySound);
  192. ExternalInterface.addCallback(<span class="string">'_setAutoPlay'</span>, _setAutoPlay);
  193. } <span class="keyword">catch</span>(e: Error) {
  194. flashDebug(<span class="string">'Fatal: ExternalInterface error: '</span> + e.toString());
  195. }
  196. } <span class="keyword">else</span> {
  197. flashDebug(<span class="string">'Fatal: ExternalInterface (Flash &amp;lt;-&amp;gt; JS) not available'</span>);
  198. };</pre></div></div>
  199. </li>
  200. <li id="section-7">
  201. <div class="annotation">
  202. <div class="pilwrap ">
  203. <a class="pilcrow" href="#section-7">&#182;</a>
  204. </div>
  205. <p>call after delay, to be safe (ensure callbacks are registered by the time JS is called below)</p>
  206. </div>
  207. <div class="content"><div class='highlight'><pre> <span class="keyword">var</span> timer: Timer = <span class="keyword">new</span> Timer(<span class="number">20</span>, <span class="number">0</span>);
  208. timer.addEventListener(TimerEvent.TIMER, <span class="keyword">function</span>() : <span class="keyword">void</span> {
  209. timer.reset();
  210. _externalInterfaceTest(<span class="literal">true</span>);</pre></div></div>
  211. </li>
  212. <li id="section-8">
  213. <div class="annotation">
  214. <div class="pilwrap ">
  215. <a class="pilcrow" href="#section-8">&#182;</a>
  216. </div>
  217. <p>timer.reset();
  218. flashDebug(&#39;Init OK&#39;);</p>
  219. </div>
  220. <div class="content"><div class='highlight'><pre> });
  221. timer.start();</pre></div></div>
  222. </li>
  223. <li id="section-9">
  224. <div class="annotation">
  225. <div class="pilwrap ">
  226. <a class="pilcrow" href="#section-9">&#182;</a>
  227. </div>
  228. <p>delayed, see above
  229. _externalInterfaceTest(true);</p>
  230. </div>
  231. <div class="content"><div class='highlight'><pre> } <span class="comment">// SoundManager2()</span>
  232. <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">flashDebug</span> <span class="params">(txt:String)</span> <span class="type">: void</span> {</span></pre></div></div>
  233. </li>
  234. <li id="section-10">
  235. <div class="annotation">
  236. <div class="pilwrap ">
  237. <a class="pilcrow" href="#section-10">&#182;</a>
  238. </div>
  239. <d>
  240. </div>
  241. <div class="content"><div class='highlight'><pre> messages.push(txt);
  242. <span class="keyword">if</span> (<span class="keyword">this</span>.flashDebugEnabled) {
  243. <span class="keyword">var</span> didCreate: Boolean = <span class="literal">false</span>;
  244. textStyle.font = <span class="string">'Arial'</span>;
  245. textStyle.size = <span class="number">12</span>;</pre></div></div>
  246. </li>
  247. <li id="section-11">
  248. <div class="annotation">
  249. <div class="pilwrap ">
  250. <a class="pilcrow" href="#section-11">&#182;</a>
  251. </div>
  252. <p>320x240 if no stage dimensions (happens in IE, apparently 0 before stage resize event fires.)</p>
  253. </div>
  254. <div class="content"><div class='highlight'><pre> <span class="keyword">var</span> w:Number = <span class="keyword">this</span>.stage.width?<span class="keyword">this</span>.stage.width:<span class="number">320</span>;
  255. <span class="keyword">var</span> h:Number = <span class="keyword">this</span>.stage.height?<span class="keyword">this</span>.stage.height:<span class="number">240</span>;
  256. <span class="keyword">if</span> (textField == <span class="literal">null</span>) {
  257. didCreate = <span class="literal">true</span>;
  258. textField = <span class="keyword">new</span> TextField();
  259. textField.autoSize = TextFieldAutoSize.LEFT;
  260. textField.x = <span class="number">0</span>;
  261. textField.y = <span class="number">0</span>;
  262. textField.multiline = <span class="literal">true</span>;
  263. textField.textColor = <span class="number">0</span>;
  264. textField.wordWrap = <span class="literal">true</span>;
  265. }
  266. textField.htmlText = messages.join(<span class="string">'\n'</span>);
  267. textField.setTextFormat(textStyle);
  268. textField.width = w;
  269. textField.height = h;
  270. <span class="keyword">if</span> (didCreate) {
  271. <span class="keyword">this</span>.addChild(textField);
  272. }
  273. }</pre></div></div>
  274. </li>
  275. <li id="section-12">
  276. <div class="annotation">
  277. <div class="pilwrap ">
  278. <a class="pilcrow" href="#section-12">&#182;</a>
  279. </div>
  280. <p></d></p>
  281. </div>
  282. <div class="content"><div class='highlight'><pre> }
  283. <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">_setAutoPlay</span><span class="params">(sID:String, autoPlay:Boolean)</span> <span class="type">: void</span> {</span>
  284. <span class="keyword">var</span> s: SoundManager2_SMSound_AS3 = soundObjects[sID];
  285. <span class="keyword">if</span> (s) {
  286. s.setAutoPlay(autoPlay);
  287. }
  288. }</pre></div></div>
  289. </li>
  290. <li id="section-13">
  291. <div class="annotation">
  292. <div class="pilwrap for-h2">
  293. <a class="pilcrow" href="#section-13">&#182;</a>
  294. </div>
  295. <h2>methods</h2>
  296. </div>
  297. <div class="content"><div class='highlight'><pre>
  298. <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">writeDebug</span> <span class="params">(s:String, logLevel:Number = 0)</span> <span class="type">: Boolean</span> {</span>
  299. <span class="keyword">if</span> (!debugEnabled) {
  300. <span class="keyword">return</span> <span class="literal">false</span>;
  301. }</pre></div></div>
  302. </li>
  303. <li id="section-14">
  304. <div class="annotation">
  305. <div class="pilwrap ">
  306. <a class="pilcrow" href="#section-14">&#182;</a>
  307. </div>
  308. <d>
  309. </div>
  310. <div class="content"><div class='highlight'><pre> ExternalInterface.call(baseJSController + <span class="string">"['_writeDebug']"</span>, <span class="string">"(Flash): "</span> + s, <span class="literal">null</span>, logLevel);</pre></div></div>
  311. </li>
  312. <li id="section-15">
  313. <div class="annotation">
  314. <div class="pilwrap ">
  315. <a class="pilcrow" href="#section-15">&#182;</a>
  316. </div>
  317. <p></d></p>
  318. </div>
  319. <div class="content"><div class='highlight'><pre> <span class="keyword">return</span> <span class="literal">true</span>;
  320. }
  321. <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">_externalInterfaceTest</span><span class="params">(isFirstCall: Boolean)</span> <span class="type">: Boolean</span> {</span>
  322. <span class="keyword">var</span> sandboxType:String = flash.system.Security[<span class="string">'sandboxType'</span>];
  323. <span class="keyword">if</span> (!didSandboxMessage &amp;&amp; sandboxType != <span class="string">'localTrusted'</span> &amp;&amp; sandboxType != <span class="string">'remote'</span>) {
  324. didSandboxMessage = <span class="literal">true</span>;
  325. flashDebug(<span class="string">'&lt;br&gt;&lt;b&gt;Fatal: Security sandbox error: Got "'</span> + sandboxType + <span class="string">'", expected "remote" or "localTrusted".&lt;br&gt;Additional security permissions need to be granted.&lt;br&gt;See &lt;a href="http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html"&gt;flash security settings panel&lt;/a&gt; for non-HTTP, eg., file:// use.&lt;/b&gt;&lt;br&gt;http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html&lt;br&gt;&lt;br&gt;You may also be able to right-click this movie and choose from the menu: &lt;br&gt;"Global Settings" -&gt; "Advanced" tab -&gt; "Trusted Location Settings"&lt;br&gt;'</span>);
  326. }
  327. <span class="keyword">try</span> {
  328. <span class="keyword">if</span> (isFirstCall == <span class="literal">true</span>) {
  329. flashDebug(<span class="string">'Testing Flash -&amp;gt; JS...'</span>);
  330. ExternalInterface.call(baseJSController + <span class="string">"._externalInterfaceOK"</span>, version);
  331. flashDebug(<span class="string">'Flash -&amp;gt; JS OK'</span>);
  332. flashDebug(<span class="string">'Waiting for JS -&amp;gt; Flash...'</span>);
  333. } <span class="keyword">else</span> {</pre></div></div>
  334. </li>
  335. <li id="section-16">
  336. <div class="annotation">
  337. <div class="pilwrap ">
  338. <a class="pilcrow" href="#section-16">&#182;</a>
  339. </div>
  340. <p>writeDebug(&#39;SM2 SWF &#39; + version + &#39; &#39; + version_as, 1);</p>
  341. </div>
  342. <div class="content"><div class='highlight'><pre> ExternalInterface.call(baseJSController + <span class="string">"._setSandboxType"</span>, sandboxType);
  343. flashDebug(<span class="string">'JS -&amp;gt; Flash OK'</span>);
  344. }
  345. } <span class="keyword">catch</span>(e: Error) {
  346. flashDebug(<span class="string">'Fatal: Flash &amp;lt;-&amp;gt; JS error: '</span> + e.toString());
  347. writeDebug(<span class="string">'_externalInterfaceTest: Error: '</span> + e.toString(), <span class="number">2</span>);
  348. <span class="keyword">if</span> (!caughtFatal) {
  349. caughtFatal = <span class="literal">true</span>;
  350. }
  351. <span class="keyword">return</span> <span class="literal">false</span>;
  352. }
  353. <span class="keyword">return</span> <span class="literal">true</span>; <span class="comment">// to verify that a call from JS to here, works. (eg. JS receives "true", thus OK.)</span>
  354. }
  355. <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">_disableDebug</span><span class="params">()</span> <span class="type">: void</span> {</span></pre></div></div>
  356. </li>
  357. <li id="section-17">
  358. <div class="annotation">
  359. <div class="pilwrap ">
  360. <a class="pilcrow" href="#section-17">&#182;</a>
  361. </div>
  362. <p>prevent future debug calls from Flash going to client (maybe improve performance)</p>
  363. </div>
  364. <div class="content"><div class='highlight'><pre> writeDebug(<span class="string">'_disableDebug()'</span>);
  365. debugEnabled = <span class="literal">false</span>;
  366. }
  367. <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">checkLoadProgress</span><span class="params">(e: Event)</span> <span class="type">: void</span> {</span>
  368. <span class="keyword">try</span> {
  369. <span class="keyword">var</span> oSound:Object = e.target;
  370. <span class="keyword">var</span> bL: int = oSound.bytesLoaded;
  371. <span class="keyword">var</span> bT: int = oSound.bytesTotal;
  372. <span class="keyword">var</span> nD: int = oSound.length || oSound.duration || <span class="number">0</span>;
  373. <span class="keyword">var</span> sMethod:String = baseJSObject + <span class="string">"['"</span> + oSound.sID + <span class="string">"']._whileloading"</span>;
  374. ExternalInterface.call(sMethod, bL, bT, nD);
  375. <span class="keyword">if</span> (bL &amp;&amp; bT &amp;&amp; bL != oSound.lastValues.bytes) {
  376. oSound.lastValues.bytes = bL;
  377. ExternalInterface.call(sMethod, bL, bT, nD);
  378. }
  379. } <span class="keyword">catch</span>(e: Error) {
  380. writeDebug(<span class="string">'checkLoadProgress(): '</span> + e.toString());
  381. }
  382. }
  383. <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">checkSoundProgress</span><span class="params">(oSound:SoundManager2_SMSound_AS3, forceCheck:Boolean = false, forceEndCheck:Boolean = false)</span> <span class="type">: void</span> {</span>
  384. <span class="keyword">var</span> bL: int = <span class="number">0</span>;
  385. <span class="keyword">var</span> bT: int = <span class="number">0</span>;
  386. <span class="keyword">var</span> nD: int = <span class="number">0</span>;
  387. <span class="keyword">var</span> nP: int = <span class="number">0</span>;
  388. <span class="keyword">var</span> bufferLength: int = <span class="number">0</span>;
  389. <span class="keyword">var</span> lP:Number = <span class="number">0</span>;
  390. <span class="keyword">var</span> rP:Number = <span class="number">0</span>;
  391. <span class="keyword">var</span> isBuffering:Object = <span class="literal">null</span>;
  392. <span class="keyword">var</span> oSoundChannel: flash.media.SoundChannel = <span class="literal">null</span>;
  393. <span class="keyword">var</span> sMethod:String = <span class="literal">null</span>;
  394. <span class="keyword">var</span> newPeakData: Boolean = <span class="literal">false</span>;
  395. <span class="keyword">var</span> newWaveformData: Boolean = <span class="literal">false</span>;
  396. <span class="keyword">var</span> newEQData: Boolean = <span class="literal">false</span>;
  397. <span class="keyword">var</span> areSoundsInaccessible: Boolean = SoundMixer.areSoundsInaccessible();
  398. <span class="keyword">var</span> isPlaying: Boolean = <span class="literal">true</span>; <span class="comment">// special case for NetStream when ending</span>
  399. <span class="keyword">var</span> hasNew:Boolean = <span class="literal">false</span>;
  400. <span class="keyword">var</span> hasNewLoaded:Boolean = <span class="literal">false</span>;
  401. <span class="keyword">if</span> (!oSound || !oSound.useEvents || oSound.failed || !oSound.connected) {</pre></div></div>
  402. </li>
  403. <li id="section-18">
  404. <div class="annotation">
  405. <div class="pilwrap ">
  406. <a class="pilcrow" href="#section-18">&#182;</a>
  407. </div>
  408. <p>edge cases for ignoring: if sounds are destructed within event handlers while checkProgress() is running, may be null</p>
  409. </div>
  410. <div class="content"><div class='highlight'><pre> <span class="keyword">return</span>;
  411. }
  412. sMethod = baseJSObject + <span class="string">"['"</span> + oSound.sID + <span class="string">"']._whileloading"</span>;
  413. <span class="keyword">if</span> (oSound.useNetstream) {</pre></div></div>
  414. </li>
  415. <li id="section-19">
  416. <div class="annotation">
  417. <div class="pilwrap ">
  418. <a class="pilcrow" href="#section-19">&#182;</a>
  419. </div>
  420. <p>Don&#39;t do anything if there is no NetStream object yet</p>
  421. </div>
  422. <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (!oSound.ns) {
  423. <span class="keyword">return</span>;
  424. }</pre></div></div>
  425. </li>
  426. <li id="section-20">
  427. <div class="annotation">
  428. <div class="pilwrap ">
  429. <a class="pilcrow" href="#section-20">&#182;</a>
  430. </div>
  431. <p>stream</p>
  432. </div>
  433. <div class="content"><div class='highlight'><pre> bufferLength = oSound.ns.bufferLength;
  434. bL = oSound.ns.bytesLoaded;
  435. bT = oSound.ns.bytesTotal;
  436. nD = int(oSound.duration || <span class="number">0</span>); <span class="comment">// can sometimes be null with short MP3s? Wack.</span>
  437. nP = oSound.ns.time * <span class="number">1000</span>;
  438. <span class="keyword">if</span> (oSound.paused) {</pre></div></div>
  439. </li>
  440. <li id="section-21">
  441. <div class="annotation">
  442. <div class="pilwrap ">
  443. <a class="pilcrow" href="#section-21">&#182;</a>
  444. </div>
  445. <p>special case: paused netStreams don&#39;t update if setPosition() is called while they are paused.
  446. instead, return lastValues.position which should reflect setPosition() call.
  447. writeDebug(&#39;paused case, setting nP of &#39;+nP+&#39; to -1&#39;);
  448. writeDebug(&#39;lastValues: &#39;+oSound.lastValues.position);</p>
  449. </div>
  450. <div class="content"><div class='highlight'><pre> nP = oSound.lastValues.position;
  451. }
  452. <span class="keyword">if</span> (nP &gt;= <span class="number">0</span> &amp;&amp; nP != oSound.lastValues.position) {
  453. oSound.lastValues.position = nP;
  454. hasNew = <span class="literal">true</span>;
  455. }
  456. <span class="keyword">if</span> (nD &gt; oSound.lastValues.duration) {
  457. oSound.lastValues.duration = nD;
  458. hasNew = <span class="literal">true</span>;
  459. }
  460. <span class="keyword">if</span> (bL &gt; oSound.lastValues.bytesLoaded) {
  461. oSound.lastValues.bytesLoaded = bL;
  462. hasNew = <span class="literal">true</span>;
  463. }
  464. <span class="keyword">if</span> (bT &gt; oSound.lastValues.bytes) {
  465. oSound.lastValues.bytes = bT;
  466. hasNew = <span class="literal">true</span>;
  467. }
  468. <span class="keyword">if</span> (bufferLength != oSound.lastValues.bufferLength) {
  469. oSound.lastValues.bufferLength = bufferLength;
  470. hasNew = <span class="literal">true</span>;
  471. }</pre></div></div>
  472. </li>
  473. <li id="section-22">
  474. <div class="annotation">
  475. <div class="pilwrap ">
  476. <a class="pilcrow" href="#section-22">&#182;</a>
  477. </div>
  478. <p>Don&#39;t set loaded for streams because bytesLoaded and bytesTotal are always 0
  479. writeDebug(&#39;ns: time/duration, bytesloaded/total: &#39;+nP+&#39;/&#39;+nD+&#39;, &#39;+bL+&#39;/&#39;+bT);</p>
  480. </div>
  481. <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (oSound.loaded != <span class="literal">true</span> &amp;&amp; nD &gt; <span class="number">0</span> &amp;&amp; bL == bT &amp;&amp; bL != <span class="number">0</span> &amp;&amp; bT != <span class="number">0</span>) {</pre></div></div>
  482. </li>
  483. <li id="section-23">
  484. <div class="annotation">
  485. <div class="pilwrap ">
  486. <a class="pilcrow" href="#section-23">&#182;</a>
  487. </div>
  488. <p>non-MP3 has loaded</p>
  489. </div>
  490. <div class="content"><div class='highlight'><pre> oSound.loaded = <span class="literal">true</span>;
  491. <span class="keyword">try</span> {
  492. ExternalInterface.call(sMethod, bL, bT, nD, bufferLength);
  493. ExternalInterface.call(baseJSObject + <span class="string">"['"</span> + oSound.sID + <span class="string">"']._onload"</span>, oSound.duration &gt; <span class="number">0</span> ? <span class="number">1</span> : <span class="number">0</span>);
  494. } <span class="keyword">catch</span>(e: Error) {
  495. writeDebug(<span class="string">'_whileLoading/_onload error: '</span> + e.toString(), <span class="number">2</span>);
  496. }
  497. } <span class="keyword">else</span> <span class="keyword">if</span> (oSound.loaded != <span class="literal">true</span> &amp;&amp; hasNew) {
  498. ExternalInterface.call(sMethod, bL, bT, nD, bufferLength);
  499. }
  500. } <span class="keyword">else</span> {</pre></div></div>
  501. </li>
  502. <li id="section-24">
  503. <div class="annotation">
  504. <div class="pilwrap ">
  505. <a class="pilcrow" href="#section-24">&#182;</a>
  506. </div>
  507. <p>MP3 sound</p>
  508. </div>
  509. <div class="content"><div class='highlight'><pre> oSoundChannel = oSound.soundChannel;
  510. bL = oSound.bytesLoaded;
  511. bT = oSound.bytesTotal;
  512. nD = int(oSound.length || <span class="number">0</span>); <span class="comment">// can sometimes be null with short MP3s? Wack.</span>
  513. isBuffering = oSound.isBuffering;
  514. <span class="keyword">if</span> (oSoundChannel) {
  515. nP = (oSoundChannel.position || <span class="number">0</span>);
  516. <span class="keyword">if</span> (oSound.lastValues.loops &gt; <span class="number">1</span> &amp;&amp; nP &gt; oSound.length) {</pre></div></div>
  517. </li>
  518. <li id="section-25">
  519. <div class="annotation">
  520. <div class="pilwrap ">
  521. <a class="pilcrow" href="#section-25">&#182;</a>
  522. </div>
  523. <p>round down to nearest loop</p>
  524. </div>
  525. <div class="content"><div class='highlight'><pre> <span class="keyword">var</span> playedLoops:Number = Math.floor(nP/oSound.length);
  526. nP = nP - (oSound.length*playedLoops);
  527. }
  528. <span class="keyword">if</span> (oSound.usePeakData) {
  529. lP = int((oSoundChannel.leftPeak) * <span class="number">1000</span>) / <span class="number">1000</span>;
  530. rP = int((oSoundChannel.rightPeak) * <span class="number">1000</span>) / <span class="number">1000</span>;
  531. } <span class="keyword">else</span> {
  532. lP = <span class="number">0</span>;
  533. rP = <span class="number">0</span>;
  534. }
  535. } <span class="keyword">else</span> {</pre></div></div>
  536. </li>
  537. <li id="section-26">
  538. <div class="annotation">
  539. <div class="pilwrap ">
  540. <a class="pilcrow" href="#section-26">&#182;</a>
  541. </div>
  542. <p>stopped, not loaded or feature not used</p>
  543. </div>
  544. <div class="content"><div class='highlight'><pre> nP = <span class="number">0</span>;
  545. }
  546. <span class="keyword">if</span> (forceEndCheck) {</pre></div></div>
  547. </li>
  548. <li id="section-27">
  549. <div class="annotation">
  550. <div class="pilwrap ">
  551. <a class="pilcrow" href="#section-27">&#182;</a>
  552. </div>
  553. <p>sound finish case: Ensure position is at end (sound duration), as flash 9 does not always correctly match the two.</p>
  554. </div>
  555. <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (nP &lt; nD) {
  556. writeDebug(<span class="string">'correcting sound '</span> + oSound.sID + <span class="string">' end position ('</span>+nP+<span class="string">') to length: '</span>+ nD, <span class="number">2</span>);
  557. nP = nD;
  558. }
  559. }
  560. <span class="keyword">if</span> (nP != oSound.lastValues.position &amp;&amp; nP !== <span class="number">0</span> &amp;&amp; !oSound.didFinish) { <span class="comment">// once "completed", sound is locked via didFinish so no more position-type events fire.</span>
  561. oSound.lastValues.position = nP;
  562. hasNew = <span class="literal">true</span>;
  563. }
  564. <span class="keyword">if</span> (nD &gt; oSound.lastValues.duration) { <span class="comment">// original sound duration * number of sound loops</span>
  565. oSound.lastValues.duration = nD;
  566. hasNew = <span class="literal">true</span>;
  567. }
  568. <span class="keyword">if</span> (bL &gt; oSound.lastValues.bytesLoaded) {
  569. oSound.lastValues.bytesLoaded = bL;
  570. hasNew = <span class="literal">true</span>;
  571. }
  572. <span class="keyword">if</span> (bT &gt; oSound.lastValues.bytes) {
  573. oSound.lastValues.bytes = bT;
  574. hasNew = <span class="literal">true</span>;
  575. hasNewLoaded = <span class="literal">true</span>;
  576. }</pre></div></div>
  577. </li>
  578. <li id="section-28">
  579. <div class="annotation">
  580. <div class="pilwrap ">
  581. <a class="pilcrow" href="#section-28">&#182;</a>
  582. </div>
  583. <p>loading progress</p>
  584. </div>
  585. <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (hasNewLoaded) {
  586. oSound.lastValues.bytes = bL;
  587. ExternalInterface.call(sMethod, bL, bT, nD);
  588. }
  589. }</pre></div></div>
  590. </li>
  591. <li id="section-29">
  592. <div class="annotation">
  593. <div class="pilwrap ">
  594. <a class="pilcrow" href="#section-29">&#182;</a>
  595. </div>
  596. <p>peak data</p>
  597. </div>
  598. <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (oSoundChannel &amp;&amp; oSound.usePeakData) {
  599. <span class="keyword">if</span> (lP != oSound.lastValues.leftPeak) {
  600. oSound.lastValues.leftPeak = lP;
  601. newPeakData = <span class="literal">true</span>;
  602. }
  603. <span class="keyword">if</span> (rP != oSound.lastValues.rightPeak) {
  604. oSound.lastValues.rightPeak = rP;
  605. newPeakData = <span class="literal">true</span>;
  606. }
  607. }
  608. <span class="keyword">var</span> newDataError:Boolean = <span class="literal">false</span>;
  609. <span class="keyword">var</span> dataError:String;</pre></div></div>
  610. </li>
  611. <li id="section-30">
  612. <div class="annotation">
  613. <div class="pilwrap ">
  614. <a class="pilcrow" href="#section-30">&#182;</a>
  615. </div>
  616. <p>special case: Netstream may try to fire whileplaying() after finishing. check that stop hasn&#39;t fired.</p>
  617. </div>
  618. <div class="content"><div class='highlight'><pre> isPlaying = (oSound.didLoad &amp;&amp; !oSound.paused &amp;&amp; (!oSound.useNetstream || (oSound.useNetstream &amp;&amp; oSound.lastNetStatus != <span class="string">"NetStream.Play.Stop"</span>))); <span class="comment">// don't update if stream has ended</span></pre></div></div>
  619. </li>
  620. <li id="section-31">
  621. <div class="annotation">
  622. <div class="pilwrap ">
  623. <a class="pilcrow" href="#section-31">&#182;</a>
  624. </div>
  625. <p>raw waveform + EQ spectrum data</p>
  626. </div>
  627. <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (isPlaying &amp;&amp; (oSoundChannel || oSound.useNetstream)) {
  628. <span class="keyword">if</span> (oSound.useWaveformData) {
  629. <span class="keyword">if</span> (!areSoundsInaccessible &amp;&amp; !oSound.handledDataError &amp;&amp; !oSound.ignoreDataError) {
  630. <span class="keyword">try</span> {
  631. oSound.getWaveformData();
  632. } <span class="keyword">catch</span>(e: Error) {
  633. <span class="keyword">if</span> (!oSound.handledDataError) {
  634. writeDebug(<span class="string">'getWaveformData() (waveform data) '</span>+e.toString());
  635. }</pre></div></div>
  636. </li>
  637. <li id="section-32">
  638. <div class="annotation">
  639. <div class="pilwrap ">
  640. <a class="pilcrow" href="#section-32">&#182;</a>
  641. </div>
  642. <p>oSound.useWaveformData = false;</p>
  643. </div>
  644. <div class="content"><div class='highlight'><pre> newDataError = <span class="literal">true</span>;
  645. dataError = e.toString();
  646. }
  647. }
  648. }
  649. <span class="keyword">if</span> (oSound.useEQData) {
  650. <span class="keyword">if</span> (!areSoundsInaccessible &amp;&amp; !oSound.handledDataError &amp;&amp; !oSound.ignoreDataError) {
  651. <span class="keyword">try</span> {
  652. oSound.getEQData();
  653. } <span class="keyword">catch</span>(e: Error) {
  654. <span class="keyword">if</span> (!oSound.handledDataError) {
  655. writeDebug(<span class="string">'computeSpectrum() (EQ data) '</span>+e.toString());
  656. }</pre></div></div>
  657. </li>
  658. <li id="section-33">
  659. <div class="annotation">
  660. <div class="pilwrap ">
  661. <a class="pilcrow" href="#section-33">&#182;</a>
  662. </div>
  663. <p>oSound.useEQData = false;</p>
  664. </div>
  665. <div class="content"><div class='highlight'><pre> newDataError = <span class="literal">true</span>;
  666. dataError = e.toString();
  667. }
  668. }
  669. }
  670. <span class="keyword">if</span> (oSound.waveformDataArray != oSound.lastValues.waveformDataArray) {
  671. oSound.lastValues.waveformDataArray = oSound.waveformDataArray;
  672. newWaveformData = <span class="literal">true</span>;
  673. }
  674. <span class="keyword">if</span> (oSound.eqDataArray != oSound.lastValues.eqDataArray) {
  675. oSound.lastValues.eqDataArray = oSound.eqDataArray;
  676. newEQData = <span class="literal">true</span>;
  677. }
  678. <span class="keyword">if</span> (newDataError &amp;&amp; !oSound.handledDataError) {
  679. sMethod = baseJSObject + <span class="string">"['"</span> + oSound.sID + <span class="string">"']._ondataerror"</span>;
  680. ExternalInterface.call(sMethod, <span class="string">'data unavailable: '</span> + dataError);
  681. oSound.handledDataError = <span class="literal">true</span>;
  682. }
  683. }
  684. <span class="keyword">if</span> (<span class="keyword">typeof</span> nP != <span class="string">'undefined'</span> &amp;&amp; (hasNew &amp;&amp; (oSound.soundChannel || oSound.useNetstream || forceCheck || forceEndCheck))) { <span class="comment">// &amp;&amp; isPlaying - removed to allow updates while paused, eg. from setPosition() calls. Also be more liberal if we're using netStream.</span></pre></div></div>
  685. </li>
  686. <li id="section-34">
  687. <div class="annotation">
  688. <div class="pilwrap ">
  689. <a class="pilcrow" href="#section-34">&#182;</a>
  690. </div>
  691. <p>oSound.lastValues.position = nP;</p>
  692. </div>
  693. <div class="content"><div class='highlight'><pre> sMethod = baseJSObject + <span class="string">"['"</span> + oSound.sID + <span class="string">"']._whileplaying"</span>;
  694. <span class="keyword">var</span> waveDataLeft:String = (newWaveformData ? oSound.waveformDataArray.slice(<span class="number">0</span>, <span class="number">256</span>).join(<span class="string">','</span>) : <span class="literal">null</span>);
  695. <span class="keyword">var</span> waveDataRight:String = (newWaveformData ? oSound.waveformDataArray.slice(<span class="number">256</span>).join(<span class="string">','</span>) : <span class="literal">null</span>);
  696. <span class="keyword">var</span> eqDataLeft:String = (newEQData ? oSound.eqDataArray.slice(<span class="number">0</span>, <span class="number">256</span>).join(<span class="string">','</span>) : <span class="literal">null</span>);
  697. <span class="keyword">var</span> eqDataRight:String = (newEQData ? oSound.eqDataArray.slice(<span class="number">256</span>).join(<span class="string">','</span>) : <span class="literal">null</span>);
  698. ExternalInterface.call(sMethod, nP, (newPeakData ? {
  699. leftPeak: lP,
  700. rightPeak: rP
  701. } : <span class="literal">null</span>), waveDataLeft, waveDataRight, (newEQData ? {
  702. leftEQ: eqDataLeft,
  703. rightEQ: eqDataRight
  704. } : <span class="literal">null</span>));
  705. }</pre></div></div>
  706. </li>
  707. <li id="section-35">
  708. <div class="annotation">
  709. <div class="pilwrap ">
  710. <a class="pilcrow" href="#section-35">&#182;</a>
  711. </div>
  712. <p>check isBuffering</p>
  713. </div>
  714. <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (!oSound.useNetstream &amp;&amp; oSound.isBuffering != oSound.lastValues.isBuffering) {</pre></div></div>
  715. </li>
  716. <li id="section-36">
  717. <div class="annotation">
  718. <div class="pilwrap ">
  719. <a class="pilcrow" href="#section-36">&#182;</a>
  720. </div>
  721. <p>property has changed</p>
  722. </div>
  723. <div class="content"><div class='highlight'><pre> oSound.lastValues.isBuffering = oSound.isBuffering;
  724. sMethod = baseJSObject + <span class="string">"['"</span> + oSound.sID + <span class="string">"']._onbufferchange"</span>;
  725. ExternalInterface.call(sMethod, oSound.isBuffering ? <span class="number">1</span> : <span class="number">0</span>);
  726. }
  727. }
  728. <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">checkProgress</span><span class="params">()</span> <span class="type">: void</span> {</span>
  729. <span class="keyword">for</span> (<span class="keyword">var</span> i: int = <span class="number">0</span>, j: int = sounds.length; i &lt; j; i++) {
  730. checkSoundProgress(soundObjects[sounds[i]]);
  731. }
  732. }
  733. <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">onLoadError</span><span class="params">(oSound:Object)</span> <span class="type">: void</span> {</span></pre></div></div>
  734. </li>
  735. <li id="section-37">
  736. <div class="annotation">
  737. <div class="pilwrap ">
  738. <a class="pilcrow" href="#section-37">&#182;</a>
  739. </div>