Actionscript 3,JQuery SWF对象插件和ExternalInterface问题
我正在尝试使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试
$('#player_external').get(0).MyFunc();
Try
$('#player_external').get(0).MyFunc();
只需附加一个 id 参数,这样您就可以直接访问 Flash 对象:
Just append an id paramter, so you can access the Flash object directly:
使用
$('#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.