2010-10-01 54 views
0

我的js代碼:ExternalInterface.addCallback工作不正常

function onFlashReady() {   
    sendToAS("sit"); 
} 

function callJS(value) {   
    onFlashReady(); 
    return "Hi Flash."; 
} 

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

HTML:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="850" Height="588" id="FlashID" tabindex="0"> 
     <param name="movie" value="BusFlex/BusProducts.swf" /> 
     <param name="quality" value="high" /> 
     <param name="wmode" value="opaque" /> 
     <param name="allowScriptAccess" value="always" /> 
     <param name="swfversion" value="6.0.65.0" /> 
     <param name="expressinstall" value="Scripts/expressInstall.swf" /> 
     <!--[if !IE]>--> 
     <object type="application/x-shockwave-flash" data="BusFlex/BusProducts.swf" width="850" height="588"> 
     <!--<![endif]--> 
     <param name="quality" value="high" /> 
     <param name="wmode" value="opaque" /> 
     <param name="allowScriptAccess" value="always" /> 
     <param name="swfversion" value="6.0.65.0" /> 
     <param name="expressinstall" value="Scripts/expressInstall.swf" /> 
     <div> 
     <h4>Установите или включите Adobe Flash Player.</h4> 
     <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p> 
     </div> 
     <!--[if !IE]>--> 
     </object> 
     <!--<![endif]--> 
     </object> 
     <script src="Scripts/swfobject_modified.js" type="text/javascript"></script> 
     <script type="text/javascript"> 
     <!-- swfobject.registerObject("FlashID"); //--> 
     </script> 
     </div> 

和ActionScript代碼:

protected function application1_creationCompleteHandler(event:FlexEvent):void 
{ 
    flash.system.Security.allowDomain("http://mysite.ru"); 
    flash.system.Security.allowDomain("http://localhost"); 
    if(ExternalInterface.available) 
    { 
      ExternalInterface.addCallback("callAS", fromJS); 
    } 
    ExternalInterface.call("callJS", "Hello JS!"); 
} 
public function fromJS(str:String):void 
{ 
    ... 
} 

但它僅在IE瀏覽器的工作原理。在FF這不起作用。請幫幫我。

回答

1

它看起來像問題是在你的Flash嵌入HTML,Mozilla瀏覽器依賴於embed標籤,但你有object再次。嘗試在你的對象節點中使用類似的東西:

<embed type="application/x-shockwave-flash" data="BusFlex/BusProducts.swf" width="850" height="588" allowscriptaccess="always"> 
</embed> 
+0

如何嵌入工作,即你必須保持雙方的對象和嵌入標籤? [Swfobject] [http://code.google.com/p/swfobject/]讓我高興地不知道這一點。 – Tjelle 2010-10-01 20:45:29

+1

是的,你會保持嵌入只是嵌套在對象內。我更喜歡swfobject,並且忽略了你正在使用它的registerObject函數。現在我不太確定這個問題,你是否確定文檔[「FlashID」]在FF中不爲空? – Dave 2010-10-01 21:07:24

1

謝謝!我正在尋找兩天的答案! 這是我的新代碼:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="850" height="588" id="FlashID" tabindex="0"> 
    <param name="movie" value="BusFlex/BusProducts.swf" /> 
    <param name="quality" value="high" /> 
    <param name="wmode" value="opaque" /> 
    <param name="allowScriptAccess" value="always" /> 
    <param name="swfversion" value="6.0.65.0" /> 
    <param name="expressinstall" value="Scripts/expressInstall.swf" /> 

    <!--[if !IE]>--> 
    <embed src="BusFlex/BusProducts.swf" type="application/x-shockwave-flash" data="BusFlex/BusProducts.swf" width="850" height="588" allowscriptaccess="always" name="FlashID"> 

     <param name="quality" value="high" /> 
     <param name="wmode" value="opaque" /> 
     <param name="allowScriptAccess" value="always" /> 
     <param name="swfversion" value="6.0.65.0" /> 
     <param name="expressinstall" value="Scripts/expressInstall.swf" /> 
     <!--<![endif]--> 

     <!--[if IE]> 
     <div> 
     <h4>YCTAHOBUTE Adobe Flash Player.</h4> 
     <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p> 
     </div> 
     <![endif]--> 
    <!--[if !IE]>--> 
    </embed> 
    <!--<![endif]--> 
    </object>