jQuery swfobject AS3 外部接口不工作
正如标题所示,我在使用 AS3ExternalInterface 和 jQuery / swfobject 时遇到了一些问题。
ActionScript :
if (ExternalInterface.available) {
ExternalInterface.call('init');
ExternalInterface.addCallback('testFunc', returnFunc)
}
function returnFunc():void {
ExternalInterface.call('alertFunc');
}
jQuery:
function init() {
alert('init');
$('#swf_object').testFunc();
}
function alertFunc() {
alert('finished');
}
显然这意味着该对象具有 id 'swf_object'
我也尝试通过以下方式获取该对象:
document.getElementById('swf_object')
document.getElementById('swf_object')[0]
$('#swf_object')[0]
无济于事。
它发出第一个警报(“init”),但不执行最后一个警报。我完全困惑,希望有人能指出我的错误! (某处肯定有一个非常明显的地方)
As you can tell by the title, I am having some trouble with AS3 ExternalInterface and jQuery / swfobject.
ActionScript :
if (ExternalInterface.available) {
ExternalInterface.call('init');
ExternalInterface.addCallback('testFunc', returnFunc)
}
function returnFunc():void {
ExternalInterface.call('alertFunc');
}
jQuery:
function init() {
alert('init');
$('#swf_object').testFunc();
}
function alertFunc() {
alert('finished');
}
Obviously that implies the object has the id 'swf_object'
I have also tried getting the object by the following:
document.getElementById('swf_object')
document.getElementById('swf_object')[0]
$('#swf_object')[0]
To no avail.
It's giving the first alert ('init') but then not doing the last one. I'm completely baffled and hope someone can point out my mistakes! (there's bound to be a massively obvious one somewhere)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于,您调用 JavaScript
init()
,而 JavaScriptinit()
会在您使 testFunc 可用之前调用 FlashtestFunc()
(仅在调用init()
完成后发生)。要解决此问题,只需将两行代码交换为:
至于在 JavaScript 中获取 Flash 对象,您可以直接使用
document.getElementById('swf_object')
来完成,但也可以使用 jQuery:The problem is that you're calling out to the JavaScript
init()
which calls the FlashtestFunc()
before you're made testFunc available (which happens only after the call out toinit()
completes).To fix this, simply swap the two lines to this:
As for getting the Flash object in JavaScript, you can do it directly with
document.getElementById('swf_object')
, but it's possible using jQuery too: