外部接口

发布于 2024-08-30 13:10:24 字数 1860 浏览 3 评论 0原文

嘿,所以我在让ExternalInterface工作时遇到了很多麻烦,这很奇怪,因为我经常使用它。

我希望这是我错过的东西,因为我已经看它太久了。

flash_ready 函数正确返回了 objectID,据我所知,其他一切都正常。

不幸的是,当我运行它时,我收到一个错误(因浏览器而异),告诉我基本上 document.getElementById().test() 不是有效的方法。

这是代码:

javascript:

function flash_ready(i){
    document.getElementById(i).test('success!'); 
}

Embed Html (生成):

<script type="text/javascript">
    swfobject.embedSWF("/chainmaille/includes/media/flash/upload_image.swf", "/chainmaille/includes/media/flash/upload_image", "500", "50", "9.0.0","expressInstall.swf", {}, {allowScriptAccess:'always', wmode:'transparent'},{id:'uploader_flash',name:'uploader_flash'});
</script>
<object type="application/x-shockwave-flash" id="uploader_flash" name="uploader_flash" data="/chainmaille/includes/media/flash/upload_image.swf" width="500" height="50"><param name="allowScriptAccess" value="always"><param name="wmode" value="transparent"></object>

AS3 :

package com.jesseditson.uploader {

  import flash.display.MovieClip;
  import flash.external.ExternalInterface;
  import flash.system.Security;

    public class UI extends MovieClip {

     // Initialization:
     public function UI() {
        Security.allowDomain('*');
        ExternalInterface.addCallback("test", test);

        var jscommand:String = "flash_ready('"+ExternalInterface.objectID+"');";
        var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
        navigateToURL(url, "_self");
    }

    public function test(t){
      trace(t);
    }
  }
}

Swfobject 正在通过谷歌代码包含在内,并且 flash 嵌入得很好,所以这不是问题。

我在另一台服务器上有一个非常相似的设置,但似乎无法在这台服务器上运行。这是一个 Hostgator 共享服务器。会不会是服务器的错?有人看到任何明显的语法问题吗?

提前致谢!

Hey, so I'm having a bunch of trouble getting ExternalInterface to work, which is odd, because I use it somewhat often.

I'm hoping it's something I just missed because I've been looking at it too long.

The flash_ready function is correctly returning the objectID, and as far as I can tell, everything else is in order.

Unfortunately, when I run it, I get an error (varying by browser) telling me that basically document.getElementById(<movename>).test() is not a valid method.

Here's the code:

javascript:

function flash_ready(i){
    document.getElementById(i).test('success!'); 
}

Embed Html (Generated):

<script type="text/javascript">
    swfobject.embedSWF("/chainmaille/includes/media/flash/upload_image.swf", "/chainmaille/includes/media/flash/upload_image", "500", "50", "9.0.0","expressInstall.swf", {}, {allowScriptAccess:'always', wmode:'transparent'},{id:'uploader_flash',name:'uploader_flash'});
</script>
<object type="application/x-shockwave-flash" id="uploader_flash" name="uploader_flash" data="/chainmaille/includes/media/flash/upload_image.swf" width="500" height="50"><param name="allowScriptAccess" value="always"><param name="wmode" value="transparent"></object>

AS3 :

package com.jesseditson.uploader {

  import flash.display.MovieClip;
  import flash.external.ExternalInterface;
  import flash.system.Security;

    public class UI extends MovieClip {

     // Initialization:
     public function UI() {
        Security.allowDomain('*');
        ExternalInterface.addCallback("test", test);

        var jscommand:String = "flash_ready('"+ExternalInterface.objectID+"');";
        var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
        navigateToURL(url, "_self");
    }

    public function test(t){
      trace(t);
    }
  }
}

Swfobject is being included via google code, and the flash embeds just fine, so that's not the problem.

I've got a very similar setup working on another server, but can't seem to get it working on this one. It's a Hostgator shared server. Could it be the server's fault? Anybody see any obvious syntax problems?

Thanks in advance!

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

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

发布评论

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

评论(5

a√萤火虫的光℡ 2024-09-06 13:10:24

Flash实际上还没有完成构建。您正在从构造函数调用 flash_ready 回调,因此 JS 会尝试在对象出现在舞台上之前进行调用。将您的 flash_ready 调用移至 Event.ADDED_TO_STAGE 侦听器,它应该开始工作。

The Flash isn't actually finished constructing yet. You're calling your flash_ready callback from the constructor, and so the JS is trying to call in before the object is on the stage. Move your flash_ready call to, say, an Event.ADDED_TO_STAGE listener and it should start working.

您的好友蓝忘机已上羡 2024-09-06 13:10:24

好的,经过进一步调查,Flash 对象的多个实例似乎存在问题,因为我将其克隆到灯箱。我现在已经开始工作了。

Ok, so after further investigation, it appears that there was a problem with multiple instances of the flash object, because I was cloning it to a lightbox. I have gotten it working now.

复古式 2024-09-06 13:10:24

刚刚花了5个小时来解决这个问题。这一切真的令人沮丧。就我而言,解决方案非常非常简单,我永远不会猜到。
首先,对于那些从未见过在浏览器内的文件上运行 Flash 播放器调试器的人,您会发现 这个引导您完成设置的链接带来了一种神奇的体验:)
现在我的外部接口发现:同一域内存在沙箱违规。这意味着 Flash 无法从 yourdomain.com 访问 www.yourdomain.com。当然,奇怪的是您没有使用ExternalInterface 显式调用域。
无论如何,解决方案非常简单:将其添加到我的 .htaccess 文件中,就是这样!

# Redirect non-www to www 
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.youtdomain.com/$1 [R=301,L] 

希望这对某人有帮助

Just spent 5 hours fighting with this. It was all really frustrating. In my case the solution was very very simple and I would have never guessed it.
So first of for all of you who have never seen the flash player debugger running on files inside your browser finding this link that walks you through the setup has resulted in a somewhat magical experience :)
Now to my ExternalInterface discovery: There was a sandbox violation inside the same domain. This meant that flash cannot access www.yourdomain.com from yourdomain.com. The weird thing of course is that you are not explicitly calling the domain with ExternalInterface.
Anyhow, the solution was very simple: add this to my .htaccess file and that was it!

# Redirect non-www to www 
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.youtdomain.com/$1 [R=301,L] 

Hope this helps someone

玩世 2024-09-06 13:10:24

flash_ready 是否收到了您期望的 objectID?

另外,为什么使用:

var jscommand:String = "flash_ready('"+ExternalInterface.objectID+"');";
var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
navigateToURL(url, "_self");

当它被设计用来做到这一点时:

ExternalInterface.call("flash_ready", ExternalInterface.objectID);

Is flash_ready receiving the objectID that you are expecting?

Also, why use:

var jscommand:String = "flash_ready('"+ExternalInterface.objectID+"');";
var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
navigateToURL(url, "_self");

When this is designed to do that:

ExternalInterface.call("flash_ready", ExternalInterface.objectID);
万劫不复 2024-09-06 13:10:24

发布您的来源(预先生成)。当您的浏览器显示 [Flash].Method 不是函数时,99% 的情况意味着您在 .swf 准备好之前尝试在 Flash 中调用函数。我看到你试图这样做,但显然它不起作用,所以一定是出了什么问题。因此,发布您的预渲染源,我相信我们可以找到问题。

Post your source (pre-generatred). When your browser says [Flash].Method is not a function, 99% of the time it means that you tried calling a function in Flash before the .swf was ready for it. I see that you tried to do that, but clearly its not working so something must be off. So post your pre-rendered source and I am sure we can find the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文