简体   繁体   English

Mozilla Firefox的Javascript和Flash通信问题

[英]Mozilla Firefox problem with Javascript and Flash communication

I have a script that displays a list of song names and when the user clicks a 'listen' button the filename is passed to a Flash player which loads and plays the mp3. 我有一个显示歌曲名称列表的脚本,当用户单击“收听”按钮时,文件名将传递到Flash播放器,该播放器将加载并播放mp3。 This works fine for Safari and IE but not in Mozilla. 这对于Safari和IE很好,但在Mozilla中却不能。 Does anyone know of any issues around Mozilla and using Javascript to pass variables to flash and call functions in flash. 是否有人知道Mozilla周围的任何问题以及是否使用Javascript将变量传递给Flash并调用Flash中的函数。

In my header file I have - 在我的头文件中-

<script type="text/javascript">
var flash;
  window.onload = function() {
     if(navigator.appName.indexOf("Microsoft") != -1) {
       flash = window.flashObject;
     }else {
       flash = window.document.flashObject;
     }
  }

AND

function PassFlash($preview_mp3){
   if(navigator.appName.indexOf("Microsoft") != -1) {
      window.flashObject.SetVariable("fileToPlay", $preview_mp3);
      window.flashObject.updatePlayer();    
   }
   else {
     window.document.flashObject.SetVariable("fileToPlay", $preview_mp3);
     window.document.flashObject.updatePlayer();
  }

Then I embed the swf like so ... 然后我像这样嵌入瑞士法郎...

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" name="flashObject" width="191" height="29" align="middle" id="flashObject">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="movie" value="preview.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffffff" />
  <embed src="preview.swf" quality="high" bgcolor="#ffffff" width="191" height="29" name="flashObject" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

The swf is successfully loaded in all browsers (main ones) but in Firefox does not appear to receive the variables or function calls that javascript passes. swf已成功在所有浏览器(主浏览器)中加载,但在Firefox中似乎未接收到JavaScript传递的变量或函数调用。

Many thanks in advance for any hints or tales of your own experience with this. 在此先非常感谢您对自己经历的任何暗示或故事。

Stephen 史提芬

+1 swfObject +1 swfObject

I think what swfObject allows you to do is to write the Flashvars into the embed code, with the same result as if you were to hardcode the flashvars in. I think trying to change the hardcoded parts in your manner would be very similar to trying to change the flashvars during runtime, after the swf has already loaded. 我认为swfObject允许您执行的操作是将Flashvars写入嵌入代码中,其结果与您对Flashvars进行硬编码相同。我认为尝试以您的方式更改硬编码部分与尝试更改硬编码部分非常相似。在swf已加载之后,在运行时更改flashvars。 Firefox may well be loading the swf once it hits the html, not giving the javascript a chance to change the code. Firefox一旦击中html,就很可能会加载swf,而不是给javascript一个更改代码的机会。

also, read up on ExternalInterface.addCallback , that might be cool if you are compiling the swfs yourself. 另外,请阅读ExternalInterface.addCallback ,如果您自己编译swfs可能会很酷。

When using javascript to communicate with Flash, I've always had the least difficulty using swfObject . 使用javascript与Flash进行通讯时,使用swfObject总是很困难。 It's just a simple javascript lib that will embed the swf and make it easy to communicate back and forth. 这只是一个简单的javascript库,它将嵌入swf并使其易于来回通信。 It works in all major browsers as well. 它也适用于所有主要浏览器。

Use swfObject . 使用swfObject Read up the documentation for it. 阅读有关它的文档。 I'm sure you'll find it a breeze :) 我相信您会发现它轻而易举:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM