Actionscript 3,JQuery SWF对象插件和ExternalInterface问题

发布于 2024-09-25 20:18:17 字数 1025 浏览 0 评论 0原文

我正在尝试使用 JQuery 及其 SWF 对象插件编写一个简单的 flash mp3 播放器。 我使用以下代码向页面添加一个 swf:

$("body").append("<div id='player_external' style='position:absolute;top:0;left:0;height:1px;width:1px;'></div>");
$('#player_external').flash({swf:"player_external.swf",wmode:"transparent",height:1,width:1,AllowScriptAccess:"always"});

播放器应该是与 javascript 交互的不可见的单像素对象。 当我从 flash 对象中调用 javascript 函数时(使用 ExternalInterface.call()),它工作正常。

但是当我尝试从 JavaScript 调用 ActionScript 函数时,什么也没有发生。 我添加了一个像这样的回调函数:

ExternalInterface.addCallback("MyFunc",MyFunc);

我已经尝试了在互联网上找到的所有可能的方法。喜欢:

$('#player_external').context.MyFunc();
$('#player_external').flash("MyFunc()"); //this just crashes browser!

另外,这里找到的解决方案: How can I call an Actionscript function when the .swf is referenced by jQuery? 没有没有帮助。 我对此放弃了希望。也许在没有 JQuery 帮助的情况下使用 flash 更好。 但应该有某种方法可以做到这一点。

谢谢。

I'm trying to write a simple flash mp3 player while using JQuery and it's SWF Object plugin.
I'm adding an swf to the page using this code:

$("body").append("<div id='player_external' style='position:absolute;top:0;left:0;height:1px;width:1px;'></div>");
$('#player_external').flash({swf:"player_external.swf",wmode:"transparent",height:1,width:1,AllowScriptAccess:"always"});

The player should be invisible one-pixel object that interacts with javascript.
When i'm calling javascript functions from within flash objects (using ExternalInterface.call()) it works fine.

But when i try to call ActionScript function from JavaScript nothing happens.
I have added a callback function like this:

ExternalInterface.addCallback("MyFunc",MyFunc);

And I've tried all possible ways I've found on the internet. Like:

$('#player_external').context.MyFunc();
$('#player_external').flash("MyFunc()"); //this just crashes browser!

Also, the solution found here: How can I call an Actionscript function when the .swf is referenced by jQuery? doesn't help.
I gave up my hope on this. Maybe it's better to use flash without JQuery's help.
But there just should be some way to do this.

Thanks.

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

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

发布评论

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

评论(3

脱离于你 2024-10-02 20:18:17

尝试 $('#player_external').get(0).MyFunc();

Try $('#player_external').get(0).MyFunc();

贱人配狗天长地久 2024-10-02 20:18:17

只需附加一个 id 参数,这样您就可以直接访问 Flash 对象:

$('#my_container').flash({
    swf: 'swf/test.swf',
    width: 740,
    height: 110,
    wmode: 'transparent',
    allowScriptAccess:'always',
    id:'my_flash',
    flashvars: {}
});

// Use document.getElementById NOT $("#my_flash") 
document.getElementById("my_flash").myInternalFlashFuctionName('Foo');

Just append an id paramter, so you can access the Flash object directly:

$('#my_container').flash({
    swf: 'swf/test.swf',
    width: 740,
    height: 110,
    wmode: 'transparent',
    allowScriptAccess:'always',
    id:'my_flash',
    flashvars: {}
});

// Use document.getElementById NOT $("#my_flash") 
document.getElementById("my_flash").myInternalFlashFuctionName('Foo');
梦醒时光 2024-10-02 20:18:17

使用 $('#myContent').get(0).method() 对我有用。使用数组引用获取第一项也可以: $('#myContent')[0].method()

我正在使用“动态”swfobject 注入。

Using $('#myContent').get(0).method() works for me. Using array reference to get the first item also works: $('#myContent')[0].method()

I'm using 'dynamic' swfobject injection.

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