2012-01-26 55 views
1

我試圖讓我的HTML頁面在我的AS3中調用我的函數,但我的JavaScript一直在說not a function。我的SWF位於同一個域中。JavaScript調用AS3錯誤

AS3:

public function Client() { 
     ExternalInterface.call('flashReady'); 
     if (ExternalInterface.available) { 
      //ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript); 
      ExternalInterface.addCallback("jsPlayStream", onPlayStreamHandler); //FLV.play() 
      ExternalInterface.addCallback("jsStopStream", onStopStreamHandler); //FLV.stop() 
      ExternalInterface.addCallback("jsSoundStream", onSoundHandler); ////FLV.volume(0 - 1) 
     } 
} 

private function onPlayStreamHandler(value:String):void { 
    flvPlayer.play(); 
} 

private function onStopStreamHandler(value:String):void { 
    flvPlayer.stop(); 
} 

private function onSoundHandler(value:Boolean):void { 
    if (value == true) { 
     flvPlayer.volume = 1; 
    } else { 
     flvPlayer.volume = 0; 
    } 
} 

JS代碼:

$("#vidPlay").click(function() { 
    if (bFlashReady == true) { 
     thisMovie("Client").jsPlayStream("play"); 
    } 
}); 

$("#vidPause").click(function() { 
    if (bFlashReady == true) { 
     thisMovie("Client").jsStopStream("stop"); 
    } 
}); 

$("#vidSoundOn").click(function() { 
    if (bFlashReady == true) { 
     thisMovie("Client").jsSoundStream(true); 
    } 
}); 

$("#vidSoundOff").click(function() { 
    if (bFlashReady == true) { 
     thisMovie("Client").jsSoundStream(false); 
    } 
}); 

function thisMovie(movieName) { 
    if (navigator.appName.indexOf("Microsoft") != -1) { 
     return window[movieName]; 
    } else { 
     return document[movieName]; 
    } 
} 

HTML:

  <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="222" height="174" id="Client" align="middle"> 
       <param name="movie" value="Client.swf?v=1.1" /> 
       <param name="quality" value="high" /> 
       <param name="bgcolor" value="#2B2B2B" /> 
       <param name="play" value="true" /> 
       <param name="loop" value="true" /> 
       <param name="wmode" value="window" /> 
       <param name="scale" value="showall" /> 
       <param name="menu" value="true" /> 
       <param name="devicefont" value="false" /> 
       <param name="salign" value="" /> 
       <param name="allowScriptAccess" value="always" /> 
       <!--[if !IE]>--> 
       <object type="application/x-shockwave-flash" data="Client.swf" width="222" height="174"> 
        <param name="movie" value="Client.swf?v=1.1" /> 
        <param name="quality" value="high" /> 
        <param name="bgcolor" value="#2B2B2B" /> 
        <param name="play" value="true" /> 
        <param name="loop" value="true" /> 
        <param name="wmode" value="window" /> 
        <param name="scale" value="showall" /> 
        <param name="menu" value="true" /> 
        <param name="devicefont" value="false" /> 
        <param name="salign" value="" /> 
        <param name="allowScriptAccess" value="always" /> 
       <!--<![endif]--> 
        <a href="http://www.adobe.com/go/getflash"> 
         <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /> 
        </a> 
       <!--[if !IE]>--> 
       </object> 
       <!--<![endif]--> 
      </object> 
+1

您應該使用'document.getElementById()'來定位您的Flash對象。這將適用於所有瀏覽器。 – Pointy

+0

你的JavaScript中聲明的「flashReady」函數在哪裏? – ToddBFisher

+0

@ToddBFisher我不好意思,我忘了在代碼段中輸入:) –

回答

2

我認爲你的代碼,發現您的Flash對象可以簡化(和可能,固定)使其使用document.getElementById()

function thisMovie(movieName) { 
    return document.getElementById(movieName); 
}