外部接口回调不起作用
我正在尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
另一种方式,只是为了调试?
要在回调函数中接收参数,只需通过 JS 发送它,并在回调函数中将其作为参数接收。
前任。:
it another way, just for debugging?
To receive a param within your callback function, just send it by JS, and receive it as an argument in your callback function.
Ex.: