/doc/generated/SoundManager2_AS3.html
HTML | 1013 lines | 739 code | 274 blank | 0 comment | 0 complexity | 267291e10f8b2e849c61b3211040e11f MD5 | raw file
- <!DOCTYPE html>
- <html>
- <head>
- <title>SoundManager2_AS3.as</title>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
- <link rel="stylesheet" media="all" href="docco.css" />
- </head>
- <body>
- <div id="container">
- <div id="background"></div>
-
- <ul id="jump_to">
- <li>
- <a class="large" href="javascript:void(0);">Jump To …</a>
- <a class="small" href="javascript:void(0);">+</a>
- <div id="jump_wrapper">
- <div id="jump_page">
-
-
- <a class="source" href="soundmanager2.html">
- soundmanager2.js
- </a>
-
-
- <a class="source" href="SoundManager2_AS.html">
- SoundManager2_AS.as
- </a>
-
-
- <a class="source" href="SoundManager2_AS3.html">
- SoundManager2_AS3.as
- </a>
-
-
- <a class="source" href="SoundManager2_SMSound_AS3.html">
- SoundManager2_SMSound_AS3.as
- </a>
-
- </div>
- </li>
- </ul>
-
- <ul class="sections">
-
- <li id="title">
- <div class="annotation">
- <h1>SoundManager2_AS3.as</h1>
- </div>
- </li>
-
-
-
- <li id="section-1">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-1">¶</a>
- </div>
-
- </div>
-
- <div class="content"><div class='highlight'><pre><span class="comment">/**
- * SoundManager 2: Javascript Sound for the Web
- * ----------------------------------------------
- * http://schillmania.com/projects/soundmanager2/
- *
- * Copyright (c) 2007, Scott Schiller. All rights reserved.
- * Code licensed under the BSD License:
- * http://www.schillmania.com/projects/soundmanager2/license.txt
- *
- * Flash 9 / ActionScript 3 version
- */</span>
-
- <span class="package"><span class="keyword">package</span> {</span>
-
- <span class="preprocessor"><span class="keyword">import</span> flash.display.Sprite;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.events.Event;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.events.IOErrorEvent;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.events.MouseEvent;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.events.SecurityErrorEvent;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.events.AsyncErrorEvent;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.events.NetStatusEvent;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.events.TimerEvent;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.external.ExternalInterface;</span> <span class="comment">// woo</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.media.Sound;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.media.SoundChannel;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.media.SoundMixer;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.net.URLLoader;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.net.URLRequest;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.system.Security;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.system.System;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.text.TextField;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.text.TextFormat;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.text.TextFieldAutoSize;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.ui.ContextMenu;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.ui.ContextMenuItem;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.utils.setInterval;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.utils.clearInterval;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.utils.Dictionary;</span>
- <span class="preprocessor"><span class="keyword">import</span> flash.utils.Timer;</span>
-
- <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>
-
- <span class="keyword">public</span> <span class="keyword">var</span> version:String = <span class="string">"V2.97a.20150601"</span>;
- <span class="keyword">public</span> <span class="keyword">var</span> version_as:String = <span class="string">"(AS3/Flash 9)"</span>;
-
- <span class="comment">/**
- * Cross-domain security options
- * HTML on foo.com loading .swf hosted on bar.com? Define your "HTML domain" here to allow JS+Flash communication to work.
- * // allow_xdomain_scripting = true;
- * // xdomain = "foo.com";
- * For all domains (possible security risk?), use xdomain = "*"; which ends up as System.security.allowDomain("*");
- * When loading from HTTPS, use System.security.allowInsecureDomain();
- * See http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/system/Security.html#allowDomain()
- */</span>
- <span class="keyword">public</span> <span class="keyword">var</span> allow_xdomain_scripting:Boolean = <span class="literal">false</span>;
- <span class="keyword">public</span> <span class="keyword">var</span> xdomain:String = <span class="string">"*"</span>;</pre></div></div>
-
- </li>
-
-
- <li id="section-2">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-2">¶</a>
- </div>
- <p>externalInterface references (for Javascript callbacks)</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> <span class="keyword">public</span> <span class="keyword">var</span> baseJSController:String = <span class="string">"soundManager"</span>;
- <span class="keyword">public</span> <span class="keyword">var</span> baseJSObject:String = baseJSController + <span class="string">".sounds"</span>;</pre></div></div>
-
- </li>
-
-
- <li id="section-3">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-3">¶</a>
- </div>
- <p>internal objects</p>
- </div>
-
- <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>
- <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>
- <span class="keyword">public</span> <span class="keyword">var</span> timer: Timer = <span class="literal">null</span>;
- <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->Flash call</span>
- <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>
- <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>
- <span class="keyword">public</span> <span class="keyword">var</span> loaded: Boolean = <span class="literal">false</span>;
- <span class="keyword">public</span> <span class="keyword">var</span> currentObject: SoundManager2_SMSound_AS3 = <span class="literal">null</span>;
- <span class="keyword">public</span> <span class="keyword">var</span> paramList:Object = <span class="literal">null</span>;
- <span class="keyword">public</span> <span class="keyword">var</span> messages:Array = [];
- <span class="keyword">public</span> <span class="keyword">var</span> textField: TextField = <span class="literal">null</span>;
- <span class="keyword">public</span> <span class="keyword">var</span> textStyle: TextFormat = <span class="keyword">new</span> TextFormat();
- <span class="keyword">public</span> <span class="keyword">var</span> didSandboxMessage: Boolean = <span class="literal">false</span>;
- <span class="keyword">public</span> <span class="keyword">var</span> caughtFatal: Boolean = <span class="literal">false</span>;
-
- <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">SoundManager2_AS3</span><span class="params">()</span> {</span>
-
- <span class="keyword">if</span> (allow_xdomain_scripting && xdomain) {
- Security.allowDomain(xdomain);
- version_as += <span class="string">' - cross-domain enabled'</span>;
- }
-
- <span class="keyword">this</span>.paramList = <span class="keyword">this</span>.root.loaderInfo.parameters;</pre></div></div>
-
- </li>
-
-
- <li id="section-4">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-4">¶</a>
- </div>
- <d>
- </div>
-
- <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>) {
- <span class="keyword">this</span>.flashDebugEnabled = <span class="literal">true</span>;
- }
-
- <span class="keyword">if</span> (<span class="keyword">this</span>.flashDebugEnabled) {
- <span class="keyword">var</span> canvas: Sprite = <span class="keyword">new</span> Sprite();
- canvas.graphics.drawRect(<span class="number">0</span>, <span class="number">0</span>, stage.stageWidth, stage.stageHeight);
- addChild(canvas);
- }</pre></div></div>
-
- </li>
-
-
- <li id="section-5">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-5">¶</a>
- </div>
- <p></d></p>
- </div>
-
- <div class="content"><div class='highlight'><pre>
- flashDebug(<span class="string">'SM2 SWF '</span> + version + <span class="string">' '</span> + version_as);</pre></div></div>
-
- </li>
-
-
- <li id="section-6">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-6">¶</a>
- </div>
- <p>context menu item with version info</p>
- </div>
-
- <div class="content"><div class='highlight'><pre>
- <span class="keyword">var</span> sm2Menu:ContextMenu = <span class="keyword">new</span> ContextMenu();
- <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);
- sm2MenuItem.enabled = <span class="literal">false</span>;
- sm2Menu.customItems.push(sm2MenuItem);
- contextMenu = sm2Menu;
-
- <span class="keyword">if</span> (ExternalInterface.available) {
- flashDebug(<span class="string">'ExternalInterface available'</span>);
- <span class="keyword">try</span> {
- flashDebug(<span class="string">'Adding ExternalInterface callbacks...'</span>);
- ExternalInterface.addCallback(<span class="string">'_load'</span>, _load);
- ExternalInterface.addCallback(<span class="string">'_unload'</span>, _unload);
- ExternalInterface.addCallback(<span class="string">'_stop'</span>, _stop);
- ExternalInterface.addCallback(<span class="string">'_start'</span>, _start);
- ExternalInterface.addCallback(<span class="string">'_pause'</span>, _pause);
- ExternalInterface.addCallback(<span class="string">'_setPosition'</span>, _setPosition);
- ExternalInterface.addCallback(<span class="string">'_setPan'</span>, _setPan);
- ExternalInterface.addCallback(<span class="string">'_setVolume'</span>, _setVolume);
- ExternalInterface.addCallback(<span class="string">'_setPolling'</span>, _setPolling);
- ExternalInterface.addCallback(<span class="string">'_externalInterfaceTest'</span>, _externalInterfaceTest);
- ExternalInterface.addCallback(<span class="string">'_disableDebug'</span>, _disableDebug);
- ExternalInterface.addCallback(<span class="string">'_getMemoryUse'</span>, _getMemoryUse);
- ExternalInterface.addCallback(<span class="string">'_createSound'</span>, _createSound);
- ExternalInterface.addCallback(<span class="string">'_destroySound'</span>, _destroySound);
- ExternalInterface.addCallback(<span class="string">'_setAutoPlay'</span>, _setAutoPlay);
- } <span class="keyword">catch</span>(e: Error) {
- flashDebug(<span class="string">'Fatal: ExternalInterface error: '</span> + e.toString());
- }
- } <span class="keyword">else</span> {
- flashDebug(<span class="string">'Fatal: ExternalInterface (Flash &lt;-&gt; JS) not available'</span>);
- };</pre></div></div>
-
- </li>
-
-
- <li id="section-7">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-7">¶</a>
- </div>
- <p>call after delay, to be safe (ensure callbacks are registered by the time JS is called below)</p>
- </div>
-
- <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>);
- timer.addEventListener(TimerEvent.TIMER, <span class="keyword">function</span>() : <span class="keyword">void</span> {
- timer.reset();
- _externalInterfaceTest(<span class="literal">true</span>);</pre></div></div>
-
- </li>
-
-
- <li id="section-8">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-8">¶</a>
- </div>
- <p>timer.reset();
- flashDebug('Init OK');</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> });
- timer.start();</pre></div></div>
-
- </li>
-
-
- <li id="section-9">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-9">¶</a>
- </div>
- <p>delayed, see above
- _externalInterfaceTest(true);</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> } <span class="comment">// SoundManager2()</span>
-
- <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>
-
- </li>
-
-
- <li id="section-10">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-10">¶</a>
- </div>
- <d>
- </div>
-
- <div class="content"><div class='highlight'><pre> messages.push(txt);
- <span class="keyword">if</span> (<span class="keyword">this</span>.flashDebugEnabled) {
- <span class="keyword">var</span> didCreate: Boolean = <span class="literal">false</span>;
- textStyle.font = <span class="string">'Arial'</span>;
- textStyle.size = <span class="number">12</span>;</pre></div></div>
-
- </li>
-
-
- <li id="section-11">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-11">¶</a>
- </div>
- <p>320x240 if no stage dimensions (happens in IE, apparently 0 before stage resize event fires.)</p>
- </div>
-
- <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>;
- <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>;
- <span class="keyword">if</span> (textField == <span class="literal">null</span>) {
- didCreate = <span class="literal">true</span>;
- textField = <span class="keyword">new</span> TextField();
- textField.autoSize = TextFieldAutoSize.LEFT;
- textField.x = <span class="number">0</span>;
- textField.y = <span class="number">0</span>;
- textField.multiline = <span class="literal">true</span>;
- textField.textColor = <span class="number">0</span>;
- textField.wordWrap = <span class="literal">true</span>;
- }
- textField.htmlText = messages.join(<span class="string">'\n'</span>);
- textField.setTextFormat(textStyle);
- textField.width = w;
- textField.height = h;
- <span class="keyword">if</span> (didCreate) {
- <span class="keyword">this</span>.addChild(textField);
- }
- }</pre></div></div>
-
- </li>
-
-
- <li id="section-12">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-12">¶</a>
- </div>
- <p></d></p>
- </div>
-
- <div class="content"><div class='highlight'><pre> }
-
- <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>
- <span class="keyword">var</span> s: SoundManager2_SMSound_AS3 = soundObjects[sID];
- <span class="keyword">if</span> (s) {
- s.setAutoPlay(autoPlay);
- }
- }</pre></div></div>
-
- </li>
-
-
- <li id="section-13">
- <div class="annotation">
-
- <div class="pilwrap for-h2">
- <a class="pilcrow" href="#section-13">¶</a>
- </div>
- <h2>methods</h2>
- </div>
-
- <div class="content"><div class='highlight'><pre>
- <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>
- <span class="keyword">if</span> (!debugEnabled) {
- <span class="keyword">return</span> <span class="literal">false</span>;
- }</pre></div></div>
-
- </li>
-
-
- <li id="section-14">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-14">¶</a>
- </div>
- <d>
- </div>
-
- <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>
-
- </li>
-
-
- <li id="section-15">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-15">¶</a>
- </div>
- <p></d></p>
- </div>
-
- <div class="content"><div class='highlight'><pre> <span class="keyword">return</span> <span class="literal">true</span>;
- }
-
- <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>
- <span class="keyword">var</span> sandboxType:String = flash.system.Security[<span class="string">'sandboxType'</span>];
- <span class="keyword">if</span> (!didSandboxMessage && sandboxType != <span class="string">'localTrusted'</span> && sandboxType != <span class="string">'remote'</span>) {
- didSandboxMessage = <span class="literal">true</span>;
- flashDebug(<span class="string">'<br><b>Fatal: Security sandbox error: Got "'</span> + sandboxType + <span class="string">'", expected "remote" or "localTrusted".<br>Additional security permissions need to be granted.<br>See <a href="http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html">flash security settings panel</a> for non-HTTP, eg., file:// use.</b><br>http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html<br><br>You may also be able to right-click this movie and choose from the menu: <br>"Global Settings" -> "Advanced" tab -> "Trusted Location Settings"<br>'</span>);
- }
- <span class="keyword">try</span> {
- <span class="keyword">if</span> (isFirstCall == <span class="literal">true</span>) {
- flashDebug(<span class="string">'Testing Flash -&gt; JS...'</span>);
- ExternalInterface.call(baseJSController + <span class="string">"._externalInterfaceOK"</span>, version);
- flashDebug(<span class="string">'Flash -&gt; JS OK'</span>);
- flashDebug(<span class="string">'Waiting for JS -&gt; Flash...'</span>);
- } <span class="keyword">else</span> {</pre></div></div>
-
- </li>
-
-
- <li id="section-16">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-16">¶</a>
- </div>
- <p>writeDebug('SM2 SWF ' + version + ' ' + version_as, 1);</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> ExternalInterface.call(baseJSController + <span class="string">"._setSandboxType"</span>, sandboxType);
- flashDebug(<span class="string">'JS -&gt; Flash OK'</span>);
- }
- } <span class="keyword">catch</span>(e: Error) {
- flashDebug(<span class="string">'Fatal: Flash &lt;-&gt; JS error: '</span> + e.toString());
- writeDebug(<span class="string">'_externalInterfaceTest: Error: '</span> + e.toString(), <span class="number">2</span>);
- <span class="keyword">if</span> (!caughtFatal) {
- caughtFatal = <span class="literal">true</span>;
- }
- <span class="keyword">return</span> <span class="literal">false</span>;
- }
- <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>
- }
-
- <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>
-
- </li>
-
-
- <li id="section-17">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-17">¶</a>
- </div>
- <p>prevent future debug calls from Flash going to client (maybe improve performance)</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> writeDebug(<span class="string">'_disableDebug()'</span>);
- debugEnabled = <span class="literal">false</span>;
- }
-
- <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>
- <span class="keyword">try</span> {
- <span class="keyword">var</span> oSound:Object = e.target;
- <span class="keyword">var</span> bL: int = oSound.bytesLoaded;
- <span class="keyword">var</span> bT: int = oSound.bytesTotal;
- <span class="keyword">var</span> nD: int = oSound.length || oSound.duration || <span class="number">0</span>;
- <span class="keyword">var</span> sMethod:String = baseJSObject + <span class="string">"['"</span> + oSound.sID + <span class="string">"']._whileloading"</span>;
- ExternalInterface.call(sMethod, bL, bT, nD);
- <span class="keyword">if</span> (bL && bT && bL != oSound.lastValues.bytes) {
- oSound.lastValues.bytes = bL;
- ExternalInterface.call(sMethod, bL, bT, nD);
- }
- } <span class="keyword">catch</span>(e: Error) {
- writeDebug(<span class="string">'checkLoadProgress(): '</span> + e.toString());
- }
- }
-
- <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>
- <span class="keyword">var</span> bL: int = <span class="number">0</span>;
- <span class="keyword">var</span> bT: int = <span class="number">0</span>;
- <span class="keyword">var</span> nD: int = <span class="number">0</span>;
- <span class="keyword">var</span> nP: int = <span class="number">0</span>;
- <span class="keyword">var</span> bufferLength: int = <span class="number">0</span>;
- <span class="keyword">var</span> lP:Number = <span class="number">0</span>;
- <span class="keyword">var</span> rP:Number = <span class="number">0</span>;
- <span class="keyword">var</span> isBuffering:Object = <span class="literal">null</span>;
- <span class="keyword">var</span> oSoundChannel: flash.media.SoundChannel = <span class="literal">null</span>;
- <span class="keyword">var</span> sMethod:String = <span class="literal">null</span>;
- <span class="keyword">var</span> newPeakData: Boolean = <span class="literal">false</span>;
- <span class="keyword">var</span> newWaveformData: Boolean = <span class="literal">false</span>;
- <span class="keyword">var</span> newEQData: Boolean = <span class="literal">false</span>;
- <span class="keyword">var</span> areSoundsInaccessible: Boolean = SoundMixer.areSoundsInaccessible();
- <span class="keyword">var</span> isPlaying: Boolean = <span class="literal">true</span>; <span class="comment">// special case for NetStream when ending</span>
- <span class="keyword">var</span> hasNew:Boolean = <span class="literal">false</span>;
- <span class="keyword">var</span> hasNewLoaded:Boolean = <span class="literal">false</span>;
-
- <span class="keyword">if</span> (!oSound || !oSound.useEvents || oSound.failed || !oSound.connected) {</pre></div></div>
-
- </li>
-
-
- <li id="section-18">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-18">¶</a>
- </div>
- <p>edge cases for ignoring: if sounds are destructed within event handlers while checkProgress() is running, may be null</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> <span class="keyword">return</span>;
- }
-
- sMethod = baseJSObject + <span class="string">"['"</span> + oSound.sID + <span class="string">"']._whileloading"</span>;
-
- <span class="keyword">if</span> (oSound.useNetstream) {</pre></div></div>
-
- </li>
-
-
- <li id="section-19">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-19">¶</a>
- </div>
- <p>Don't do anything if there is no NetStream object yet</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (!oSound.ns) {
- <span class="keyword">return</span>;
- }</pre></div></div>
-
- </li>
-
-
- <li id="section-20">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-20">¶</a>
- </div>
- <p>stream</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> bufferLength = oSound.ns.bufferLength;
- bL = oSound.ns.bytesLoaded;
- bT = oSound.ns.bytesTotal;
- nD = int(oSound.duration || <span class="number">0</span>); <span class="comment">// can sometimes be null with short MP3s? Wack.</span>
- nP = oSound.ns.time * <span class="number">1000</span>;
-
- <span class="keyword">if</span> (oSound.paused) {</pre></div></div>
-
- </li>
-
-
- <li id="section-21">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-21">¶</a>
- </div>
- <p>special case: paused netStreams don't update if setPosition() is called while they are paused.
- instead, return lastValues.position which should reflect setPosition() call.
- writeDebug('paused case, setting nP of '+nP+' to -1');
- writeDebug('lastValues: '+oSound.lastValues.position);</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> nP = oSound.lastValues.position;
- }
-
- <span class="keyword">if</span> (nP >= <span class="number">0</span> && nP != oSound.lastValues.position) {
- oSound.lastValues.position = nP;
- hasNew = <span class="literal">true</span>;
- }
- <span class="keyword">if</span> (nD > oSound.lastValues.duration) {
- oSound.lastValues.duration = nD;
- hasNew = <span class="literal">true</span>;
- }
- <span class="keyword">if</span> (bL > oSound.lastValues.bytesLoaded) {
- oSound.lastValues.bytesLoaded = bL;
- hasNew = <span class="literal">true</span>;
- }
- <span class="keyword">if</span> (bT > oSound.lastValues.bytes) {
- oSound.lastValues.bytes = bT;
- hasNew = <span class="literal">true</span>;
- }
- <span class="keyword">if</span> (bufferLength != oSound.lastValues.bufferLength) {
- oSound.lastValues.bufferLength = bufferLength;
- hasNew = <span class="literal">true</span>;
- }</pre></div></div>
-
- </li>
-
-
- <li id="section-22">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-22">¶</a>
- </div>
- <p>Don't set loaded for streams because bytesLoaded and bytesTotal are always 0
- writeDebug('ns: time/duration, bytesloaded/total: '+nP+'/'+nD+', '+bL+'/'+bT);</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (oSound.loaded != <span class="literal">true</span> && nD > <span class="number">0</span> && bL == bT && bL != <span class="number">0</span> && bT != <span class="number">0</span>) {</pre></div></div>
-
- </li>
-
-
- <li id="section-23">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-23">¶</a>
- </div>
- <p>non-MP3 has loaded</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> oSound.loaded = <span class="literal">true</span>;
- <span class="keyword">try</span> {
- ExternalInterface.call(sMethod, bL, bT, nD, bufferLength);
- ExternalInterface.call(baseJSObject + <span class="string">"['"</span> + oSound.sID + <span class="string">"']._onload"</span>, oSound.duration > <span class="number">0</span> ? <span class="number">1</span> : <span class="number">0</span>);
- } <span class="keyword">catch</span>(e: Error) {
- writeDebug(<span class="string">'_whileLoading/_onload error: '</span> + e.toString(), <span class="number">2</span>);
- }
- } <span class="keyword">else</span> <span class="keyword">if</span> (oSound.loaded != <span class="literal">true</span> && hasNew) {
- ExternalInterface.call(sMethod, bL, bT, nD, bufferLength);
- }
-
- } <span class="keyword">else</span> {</pre></div></div>
-
- </li>
-
-
- <li id="section-24">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-24">¶</a>
- </div>
- <p>MP3 sound</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> oSoundChannel = oSound.soundChannel;
- bL = oSound.bytesLoaded;
- bT = oSound.bytesTotal;
- nD = int(oSound.length || <span class="number">0</span>); <span class="comment">// can sometimes be null with short MP3s? Wack.</span>
- isBuffering = oSound.isBuffering;
-
- <span class="keyword">if</span> (oSoundChannel) {
- nP = (oSoundChannel.position || <span class="number">0</span>);
- <span class="keyword">if</span> (oSound.lastValues.loops > <span class="number">1</span> && nP > oSound.length) {</pre></div></div>
-
- </li>
-
-
- <li id="section-25">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-25">¶</a>
- </div>
- <p>round down to nearest loop</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> <span class="keyword">var</span> playedLoops:Number = Math.floor(nP/oSound.length);
- nP = nP - (oSound.length*playedLoops);
- }
- <span class="keyword">if</span> (oSound.usePeakData) {
- lP = int((oSoundChannel.leftPeak) * <span class="number">1000</span>) / <span class="number">1000</span>;
- rP = int((oSoundChannel.rightPeak) * <span class="number">1000</span>) / <span class="number">1000</span>;
- } <span class="keyword">else</span> {
- lP = <span class="number">0</span>;
- rP = <span class="number">0</span>;
- }
- } <span class="keyword">else</span> {</pre></div></div>
-
- </li>
-
-
- <li id="section-26">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-26">¶</a>
- </div>
- <p>stopped, not loaded or feature not used</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> nP = <span class="number">0</span>;
- }
-
- <span class="keyword">if</span> (forceEndCheck) {</pre></div></div>
-
- </li>
-
-
- <li id="section-27">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-27">¶</a>
- </div>
- <p>sound finish case: Ensure position is at end (sound duration), as flash 9 does not always correctly match the two.</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (nP < nD) {
- 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>);
- nP = nD;
- }
- }
-
- <span class="keyword">if</span> (nP != oSound.lastValues.position && nP !== <span class="number">0</span> && !oSound.didFinish) { <span class="comment">// once "completed", sound is locked via didFinish so no more position-type events fire.</span>
- oSound.lastValues.position = nP;
- hasNew = <span class="literal">true</span>;
- }
-
- <span class="keyword">if</span> (nD > oSound.lastValues.duration) { <span class="comment">// original sound duration * number of sound loops</span>
- oSound.lastValues.duration = nD;
- hasNew = <span class="literal">true</span>;
- }
-
- <span class="keyword">if</span> (bL > oSound.lastValues.bytesLoaded) {
- oSound.lastValues.bytesLoaded = bL;
- hasNew = <span class="literal">true</span>;
- }
-
- <span class="keyword">if</span> (bT > oSound.lastValues.bytes) {
- oSound.lastValues.bytes = bT;
- hasNew = <span class="literal">true</span>;
- hasNewLoaded = <span class="literal">true</span>;
- }</pre></div></div>
-
- </li>
-
-
- <li id="section-28">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-28">¶</a>
- </div>
- <p>loading progress</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (hasNewLoaded) {
- oSound.lastValues.bytes = bL;
- ExternalInterface.call(sMethod, bL, bT, nD);
- }
-
- }</pre></div></div>
-
- </li>
-
-
- <li id="section-29">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-29">¶</a>
- </div>
- <p>peak data</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (oSoundChannel && oSound.usePeakData) {
- <span class="keyword">if</span> (lP != oSound.lastValues.leftPeak) {
- oSound.lastValues.leftPeak = lP;
- newPeakData = <span class="literal">true</span>;
- }
- <span class="keyword">if</span> (rP != oSound.lastValues.rightPeak) {
- oSound.lastValues.rightPeak = rP;
- newPeakData = <span class="literal">true</span>;
- }
- }
-
- <span class="keyword">var</span> newDataError:Boolean = <span class="literal">false</span>;
- <span class="keyword">var</span> dataError:String;</pre></div></div>
-
- </li>
-
-
- <li id="section-30">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-30">¶</a>
- </div>
- <p>special case: Netstream may try to fire whileplaying() after finishing. check that stop hasn't fired.</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> isPlaying = (oSound.didLoad && !oSound.paused && (!oSound.useNetstream || (oSound.useNetstream && oSound.lastNetStatus != <span class="string">"NetStream.Play.Stop"</span>))); <span class="comment">// don't update if stream has ended</span></pre></div></div>
-
- </li>
-
-
- <li id="section-31">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-31">¶</a>
- </div>
- <p>raw waveform + EQ spectrum data</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (isPlaying && (oSoundChannel || oSound.useNetstream)) {
-
- <span class="keyword">if</span> (oSound.useWaveformData) {
- <span class="keyword">if</span> (!areSoundsInaccessible && !oSound.handledDataError && !oSound.ignoreDataError) {
- <span class="keyword">try</span> {
- oSound.getWaveformData();
- } <span class="keyword">catch</span>(e: Error) {
- <span class="keyword">if</span> (!oSound.handledDataError) {
- writeDebug(<span class="string">'getWaveformData() (waveform data) '</span>+e.toString());
- }</pre></div></div>
-
- </li>
-
-
- <li id="section-32">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-32">¶</a>
- </div>
- <p>oSound.useWaveformData = false;</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> newDataError = <span class="literal">true</span>;
- dataError = e.toString();
- }
- }
- }
-
- <span class="keyword">if</span> (oSound.useEQData) {
- <span class="keyword">if</span> (!areSoundsInaccessible && !oSound.handledDataError && !oSound.ignoreDataError) {
- <span class="keyword">try</span> {
- oSound.getEQData();
- } <span class="keyword">catch</span>(e: Error) {
- <span class="keyword">if</span> (!oSound.handledDataError) {
- writeDebug(<span class="string">'computeSpectrum() (EQ data) '</span>+e.toString());
- }</pre></div></div>
-
- </li>
-
-
- <li id="section-33">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-33">¶</a>
- </div>
- <p>oSound.useEQData = false;</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> newDataError = <span class="literal">true</span>;
- dataError = e.toString();
- }
- }
- }
-
- <span class="keyword">if</span> (oSound.waveformDataArray != oSound.lastValues.waveformDataArray) {
- oSound.lastValues.waveformDataArray = oSound.waveformDataArray;
- newWaveformData = <span class="literal">true</span>;
- }
-
- <span class="keyword">if</span> (oSound.eqDataArray != oSound.lastValues.eqDataArray) {
- oSound.lastValues.eqDataArray = oSound.eqDataArray;
- newEQData = <span class="literal">true</span>;
- }
-
- <span class="keyword">if</span> (newDataError && !oSound.handledDataError) {
- sMethod = baseJSObject + <span class="string">"['"</span> + oSound.sID + <span class="string">"']._ondataerror"</span>;
- ExternalInterface.call(sMethod, <span class="string">'data unavailable: '</span> + dataError);
- oSound.handledDataError = <span class="literal">true</span>;
- }
-
- }
-
- <span class="keyword">if</span> (<span class="keyword">typeof</span> nP != <span class="string">'undefined'</span> && (hasNew && (oSound.soundChannel || oSound.useNetstream || forceCheck || forceEndCheck))) { <span class="comment">// && isPlaying - removed to allow updates while paused, eg. from setPosition() calls. Also be more liberal if we're using netStream.</span></pre></div></div>
-
- </li>
-
-
- <li id="section-34">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-34">¶</a>
- </div>
- <p>oSound.lastValues.position = nP;</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> sMethod = baseJSObject + <span class="string">"['"</span> + oSound.sID + <span class="string">"']._whileplaying"</span>;
- <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>);
- <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>);
- <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>);
- <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>);
- ExternalInterface.call(sMethod, nP, (newPeakData ? {
- leftPeak: lP,
- rightPeak: rP
- } : <span class="literal">null</span>), waveDataLeft, waveDataRight, (newEQData ? {
- leftEQ: eqDataLeft,
- rightEQ: eqDataRight
- } : <span class="literal">null</span>));
- }</pre></div></div>
-
- </li>
-
-
- <li id="section-35">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-35">¶</a>
- </div>
- <p>check isBuffering</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (!oSound.useNetstream && oSound.isBuffering != oSound.lastValues.isBuffering) {</pre></div></div>
-
- </li>
-
-
- <li id="section-36">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-36">¶</a>
- </div>
- <p>property has changed</p>
- </div>
-
- <div class="content"><div class='highlight'><pre> oSound.lastValues.isBuffering = oSound.isBuffering;
- sMethod = baseJSObject + <span class="string">"['"</span> + oSound.sID + <span class="string">"']._onbufferchange"</span>;
- ExternalInterface.call(sMethod, oSound.isBuffering ? <span class="number">1</span> : <span class="number">0</span>);
- }
-
- }
-
- <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>
- <span class="keyword">for</span> (<span class="keyword">var</span> i: int = <span class="number">0</span>, j: int = sounds.length; i < j; i++) {
- checkSoundProgress(soundObjects[sounds[i]]);
- }
- }
-
- <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>
-
- </li>
-
-
- <li id="section-37">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-37">¶</a>
- </div>
-