外部接口回调不起作用

发布于 2024-12-12 03:37:51 字数 1533 浏览 3 评论 0原文

我正在尝试从 JavaScript 调用 ActionScript 中的函数,我已经成功地使用另一个 Flash 文件成功地执行了此操作,但在当前的 Flash 文件中由于某种原因失败了。我正在使用 jQuery SWFEmbed,这是我的 JS 代码:

$.ajax({
        url: '<?php echo $html->url(array('controller' => 'voicenotes', 'action' => 'get_url'), true);?>' + '/' + container.children('#VoicenoteVnid').val(),
        dataType: 'json',
        type: 'POST',
        success: function(response) {
          container.children('.voicenote-info').children('.player').addClass('active');
          flashMovie = container.children('.voicenote-info').children('.player');
          alert(flashMovie.html());
          flashMovie.flash({
            swf: '<?php echo $html->url('/files/flash/reproductor_compact.swf',true); ?>',
            width: 240,
            height: 40,
            quality: "high",
            wmode: "transparent",
            allowscriptaccess: "always",
          });
          alert($('.player.active > object')[0].callIt());
        }              
      });

这是我的 AS 代码,这是在我的构造函数中:

public function reproductor()
        {
            ExternalInterface.addCallback("callIt", test);
            ExternalInterface.call("alert", "Que fue?");
            trace(ExternalInterface.available);
        }

这是我的函数:

private function test():String {
            return "this is a test";
        }

ExternalInterface.call 工作,跟踪输出 true,我不知道发生了什么在。

PS:如果您还可以告诉我如何将参数传递给ExternalInterface 回调,我将不胜感激。

I'm trying to call a function in my ActionScript from my JavaScript, I've managed to successfully do this with another flash file but in the current one it's failing for some reason. I'm using jQuery SWFEmbed, this is my JS code:

$.ajax({
        url: '<?php echo $html->url(array('controller' => 'voicenotes', 'action' => 'get_url'), true);?>' + '/' + container.children('#VoicenoteVnid').val(),
        dataType: 'json',
        type: 'POST',
        success: function(response) {
          container.children('.voicenote-info').children('.player').addClass('active');
          flashMovie = container.children('.voicenote-info').children('.player');
          alert(flashMovie.html());
          flashMovie.flash({
            swf: '<?php echo $html->url('/files/flash/reproductor_compact.swf',true); ?>',
            width: 240,
            height: 40,
            quality: "high",
            wmode: "transparent",
            allowscriptaccess: "always",
          });
          alert($('.player.active > object')[0].callIt());
        }              
      });

And here is my AS code, this is in my constructor:

public function reproductor()
        {
            ExternalInterface.addCallback("callIt", test);
            ExternalInterface.call("alert", "Que fue?");
            trace(ExternalInterface.available);
        }

And this is my function:

private function test():String {
            return "this is a test";
        }

The ExternalInterface.call work, and the trace outputs true, I have no idea what's going on.

P.S: If you could also tell me how I can pass parameters to a ExternalInterface callback I'd appreciate it.

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

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

发布评论

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

评论(1

人事已非 2024-12-19 03:37:51
  1. 也许您查找 SWF 对象的 Jquery 选择器是错误的。你为什么不尝试做
    另一种方式,只是为了调试?
  2. 也许您正在 SWF 完全加载之前调用 AS3 函数。为什么不尝试将该函数调用(callIt)放入一个按钮中,在 Ajax 之外,并在调用警报后按下它?

要在回调函数中接收参数,只需通过 JS 发送它,并在回调函数中将其作为参数接收。
前任。:

$('.player.active > object')[0].callIt("LOLSOME")

...

ExternalInterface.addCallback("callIt", test);
private function test(arg:String):String {
        return "param received from JS: " + arg;
}
  1. Maybe your Jquery selector to find your SWF object is wrong. Why don't you try to do
    it another way, just for debugging?
  2. Maybe you are calling your AS3 function before the SWF has fully loaded. Why don't you try place that function call(callIt) into an button, outsite that Ajax, and press it after your alert have been called?

To receive a param within your callback function, just send it by JS, and receive it as an argument in your callback function.
Ex.:

$('.player.active > object')[0].callIt("LOLSOME")

...

ExternalInterface.addCallback("callIt", test);
private function test(arg:String):String {
        return "param received from JS: " + arg;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文