Firefox 的 Flash 外部接口问题

发布于 2024-07-20 00:27:34 字数 1925 浏览 5 评论 0原文

我很难让ExternalInterface 在 Firefox 上运行。 我正在尝试从 javascript 调用 AS3 函数。 SWF 已使用正确的回调进行设置,并且可以在 IE 中运行。

我正在使用 AC_RunActiveContent.js 将 swf 嵌入到我的页面中。 不过,我对其进行了修改,将 ID 添加到对象/嵌入标签中。 下面是分别为 IE 和 Firefox 生成的对象和嵌入标记。

    <object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400" height="400" align="middle" id="jpeg_encoder2" name="jpeg_encoder3" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" >
    <param name="movie" value="/jpeg_encoder/jpeg_encoder3.swf" /> 
    <param name="quality" value="high" /> 
    <param name="play" value="true" /> 
    <param name="loop" value="true" /> 
    <param name="scale" value="showall" /> 
    <param name="wmode" value="window" /> 
    <param name="devicefont" value="false" /> 
    <param name="bgcolor" value="#ffffff" /> 
    <param name="menu" value="false" /> 
    <param name="allowFullScreen" value="false" /> 
    <param name="allowScriptAccess" value="always" /> 
</object>


<embed 
    width="400" 
    height="400" 
    src="/jpeg_encoder/jpeg_encoder3.swf" 
    quality="high" 
    pluginspage="http://www.macromedia.com/go/getflashplayer" 
    align="middle" 
    play="true" 
    loop="true" 
    scale="showall" 
    wmode="window" 
    devicefont="false" 
    id="jpeg_encoder2" 
    bgcolor="#ffffff" 
    name="jpeg_encoder3" 
    menu="false" 
    allowFullScreen="false" 
    allowScriptAccess="always" 
    type="application/x-shockwave-flash" > 
</embed>

我正在这样调用该函数...

<script>
try {
    document.getElementById('jpeg_encoder2').processImage(z);
} catch (e) { alert(e.message); }
</script>

在 Firefox 中,我收到一条错误消息“document.getElementById("jpeg_encoder2").processImage is not a function

有什么想法吗?

I am having a hard time getting ExternalInterface to work on Firefox. I am trying to call a AS3 function from javascript. The SWF is setup with the right callbacks and it is working in IE.

I am using AC_RunActiveContent.js to embed the swf into my page. However, I have modified it to add an ID to the Object / Embed Tags. Below are object and embed tag that are generated for IE and for Firefox respectively.

    <object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400" height="400" align="middle" id="jpeg_encoder2" name="jpeg_encoder3" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" >
    <param name="movie" value="/jpeg_encoder/jpeg_encoder3.swf" /> 
    <param name="quality" value="high" /> 
    <param name="play" value="true" /> 
    <param name="loop" value="true" /> 
    <param name="scale" value="showall" /> 
    <param name="wmode" value="window" /> 
    <param name="devicefont" value="false" /> 
    <param name="bgcolor" value="#ffffff" /> 
    <param name="menu" value="false" /> 
    <param name="allowFullScreen" value="false" /> 
    <param name="allowScriptAccess" value="always" /> 
</object>


<embed 
    width="400" 
    height="400" 
    src="/jpeg_encoder/jpeg_encoder3.swf" 
    quality="high" 
    pluginspage="http://www.macromedia.com/go/getflashplayer" 
    align="middle" 
    play="true" 
    loop="true" 
    scale="showall" 
    wmode="window" 
    devicefont="false" 
    id="jpeg_encoder2" 
    bgcolor="#ffffff" 
    name="jpeg_encoder3" 
    menu="false" 
    allowFullScreen="false" 
    allowScriptAccess="always" 
    type="application/x-shockwave-flash" > 
</embed>

I am calling the function like this...

<script>
try {
    document.getElementById('jpeg_encoder2').processImage(z);
} catch (e) { alert(e.message); }
</script>

In Firefox, I get an error saying "document.getElementById("jpeg_encoder2").processImage is not a function"

Any Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

终陌 2024-07-27 00:27:34

尝试以下两件事:

首先,尝试像这样从 Javascript 调用该函数:

var swf;
if(navigator.appName.indexOf("Microsoft") != -1) {
    swf = window["jpeg_encoder2"];
} else {
    swf = document["jpeg_encoder2"];
}
if(typeof(swf) == "undefined") swf = document.getElementById("jpeg_encoder2");

swf.processImage(z);

其次,我发现 Firefox 中的ExternalInterface 调用似乎只适用于嵌入标签,而不适用于对象标签。 看看如果您只使用嵌入标签是否可以让它工作。 (现在,我不清楚您发布的 HTML/Javascript 组合是否会访问该对象或嵌入元素。)

Try these two things:

First, try calling the function from Javascript like this:

var swf;
if(navigator.appName.indexOf("Microsoft") != -1) {
    swf = window["jpeg_encoder2"];
} else {
    swf = document["jpeg_encoder2"];
}
if(typeof(swf) == "undefined") swf = document.getElementById("jpeg_encoder2");

swf.processImage(z);

Second, I've found that ExternalInterface calls in Firefox seem to only work with embed tags, not object tags. See if you can get it to work if you just use an embed tag. (Right now, I'm not clear whether the HTML/Javascript combo you've posted will access the object or the embed element.)

心凉怎暖 2024-07-27 00:27:34

嗯,你是否使用 addCallback 将你的 actionscript 函数暴露给了 Javascript?

有关 addCallback 的 Adob​​e 文档

Hmm, did you expose your actionscript function to Javascript with addCallback ?

Adobe documentation on addCallback

栖迟 2024-07-27 00:27:34

下面是如何将 Flash 影片放置在 html 页面中的示例。 这部电影是非常简单的电影,开头有一个停止动作。 该电影在下面的“测试运行”主题下显示。 这个特定的 html 代码是由 FlashMX 的 Publish 命令自动生成的。 请注意,Flash 影片文件是 simplemovie.swf; Flash 已自动分配 ID 和名称以匹配电影文件名(减去 .swf 扩展名)。 实际上,名称和 ID 可以是任何东西(但不要使用通俗名称,特别是不要以数字开头),只要它没有被同一页面中的任何其他元素使用即可。

<代码>
`codebase="http://download.macromedia.com/pub/shockwave/cabs/flash`/swflash.cab#version=6,0,0,0"
` WIDTH="150" HEIGHT="75" id="simplemovie" ALIGN="">
<代码>
<代码>
<代码>
<代码>
` 质量=中
` swliveconnect =“真”
` bgcolor=#FFFFFF 宽度=“150” 高度=“75”
` 名称=“简单电影”
` 对齐=""
`TYPE =“应用程序/x-shockwave-flash”
` PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
<代码>

flash 文件中有一个播放函数,以下函数将调用该函数:

function testEval(stringToEval)
{
  var movie=eval(stringToEval);
  if (movie)
  {
    if (movie.PercentLoaded())
    {
      if (movie.PercentLoaded()==100)
      {
        movie.Play();
      }
      else
      {
        alert("movie is still loading, try again soon");
      }
    }
    else
    {
      alert("movie object found-but unable to send command"); 
    }
  }
  else
  {
    alert("movie object not found");
  }
}

Below is an example of how a Flash movie is placed within a html page. This movie is very simple movie with a stop action at the beginning. The movie is shown below under Test Runs subject. This particular html code was auto generated by FlashMX's Publish command. Notice that the Flash movie file is simplemovie.swf; and an id and a name have been assigned automatically by Flash to match the movie filename (minus the .swf extension). In reality, the name and id could be anything (but do not use exoteric names, especially, do not start with a number), as long as it has not been used by any other element in the same page.


`codebase="http://download.macromedia.com/pub/shockwave/cabs/flash`/swflash.cab#version=6,0,0,0"

` WIDTH="150" HEIGHT="75" id="simplemovie" ALIGN="">




` quality=medium

` swliveconnect="true"
` bgcolor=#FFFFFF WIDTH="150" HEIGHT="75"
` name="simplemovie"
` ALIGN=""
`TYPE="application/x-shockwave-flash"
` PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">

there is a play function in the flash file the following function will calls that function:

function testEval(stringToEval)
{
  var movie=eval(stringToEval);
  if (movie)
  {
    if (movie.PercentLoaded())
    {
      if (movie.PercentLoaded()==100)
      {
        movie.Play();
      }
      else
      {
        alert("movie is still loading, try again soon");
      }
    }
    else
    {
      alert("movie object found-but unable to send command"); 
    }
  }
  else
  {
    alert("movie object not found");
  }
}
桃酥萝莉 2024-07-27 00:27:34

请参阅此帖子

您需要一个更像这样的 JS 函数来检索 Flash 对象(而不是 getElemById):

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

并确保在加载文档之前不要调用此函数。

See this post.

You want a JS function more like this to retrieve the Flash object (rather than getElemById):

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

And make sure not to call this function until the document is loaded.

旧时模样 2024-07-27 00:27:34

尝试在 objectembed 标记中使用相同的 ID。 我记得一个浏览器使用一个标签,另一个浏览器使用另一个......不知道哪个是哪个。 我前段时间也遇到过同样的问题。

我通过修改 示例代码 自带闪光灯。 确保它能工作,然后将其剥离并进行调整以供我使用。

在示例中,请注意 object 标记的 id 设置为“ExternalInterfaceExample”,然后 embed 标记的 name > 参数也设置为“ExternalInterfaceExample”。 我想这可能是你的线索。

祝你好运!

Try having the same id in both object and embed tags. I remember one browser is using one tag and another browser the other...don't know which one is which. I had the same issue some time ago.

I'm got around by modifying the Example Code that comes with flash. Making sure it works, then stripping it down and adapting it for my use.

In the example notice that the object tag the id set to "ExternalInterfaceExample", then the embed tag has the name parameter set to "ExternalInterfaceExample" as well. I think that might be your clue.

Good luck!

执笔绘流年 2024-07-27 00:27:34

在尝试调用它们之前,您的 swf 是否可见(在页面上)? 如果没有,请阅读以下内容: swf-直到可见才初始化

Are your swf's visible (on the page) before you try calling them? If not, read this: swf-not-initializing-until-visible

凉宸 2024-07-27 00:27:34

如果您不使用 AC_RunActiveContent.js 来嵌入 Flash 影片,而是使用 swfobject,则有一种简单的内置方法可以实现这一点。

<head>
 <script type="text/javascript" src="swfobject.js"></script>

 <script type="text/javascript">
 try {
      swfobject.getObjectById('jpeg_encoder2').processImage(z); 
      } catch (e) { alert(e.message); }
 </script>
</head>

如果您不使用 swfObject,您可以直接将 swfobject.getObjectById 复制并粘贴到您的代码中:

<script type="text/javascript">

function getObjectById(objectIdStr) {
        var r = null;
        var o = getElementById(objectIdStr);
        if (o && o.nodeName == "OBJECT") {
            if (typeof o.SetVariable != UNDEF) {
                r = o;
            }
            else {
                var n = o.getElementsByTagName(OBJECT)[0];
                if (n) {
                    r = n;
                }
            }
        }
        return r;

getObjectById('jpeg_encoder2').processImage(z); //call your method 
</script>

If instead of using AC_RunActiveContent.js to embed your flash movie you use swfobject there is a easy build-in way of doing that.

<head>
 <script type="text/javascript" src="swfobject.js"></script>

 <script type="text/javascript">
 try {
      swfobject.getObjectById('jpeg_encoder2').processImage(z); 
      } catch (e) { alert(e.message); }
 </script>
</head>

If you are not using swfObject you could just copy and paste swfobject.getObjectById straight in to your code:

<script type="text/javascript">

function getObjectById(objectIdStr) {
        var r = null;
        var o = getElementById(objectIdStr);
        if (o && o.nodeName == "OBJECT") {
            if (typeof o.SetVariable != UNDEF) {
                r = o;
            }
            else {
                var n = o.getElementsByTagName(OBJECT)[0];
                if (n) {
                    r = n;
                }
            }
        }
        return r;

getObjectById('jpeg_encoder2').processImage(z); //call your method 
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文