我有一个简单的闪存套接字,用于连接到IRC服务器。它通过open
向JS提供close
,send
和ExternalInterface
方法,分别用于打开连接,关闭连接和发送消息。无论何时获取消息,套接字都会在JS中调用IRC.io.receive
,该消息由JS解析为有用的消息。
不幸的是,每当从JS调用任何flash方法时,它们都会返回“__不是函数”错误。
这是(淡化)AS,其中IRC是文档类:
public class IRC extends MovieClip {
public static function open(url:String, port:int) {/* code */}
public static function close(port:int) {/* code */}
public static function send(port:int, message:String) {/* code */}
public function IRC() {
ExternalInterface.addCallback('send', IRC.send);
ExternalInterface.addCallback('open', IRC.open);
ExternalInterface.addCallback('close', IRC.close);
}
}
和HTML / JS:
<html>
<head>
<script type="text/javascript">
window.IRC = {
io: {}
};
IRC.io.receive = function(message) {/* code */}
IRC.io.send = function(port, str) {
document.getElementById('socket').send(port, str);
}
IRC.io.open = function(url, port) {
document.getElementById('socket').open(url, port);
}
IRC.io.close = function(port) {
document.getElementById('socket').close(port);
}
</script>
</head>
<body>
<!-- ui -->
<embed src="socket.swf" quality="high" allowscriptsaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="false" style="display:none;">
</body>
<html>
对ExternalInterface
注册的任何函数的任何调用都会抛出“函数不存在”异常。我做错了吗?
答案 0 :(得分:1)
当瑞士法郎准备接听电话时,请尝试发信号。
例如,在您的ActionScript中:
ExternalInterface.call('initIRQ');
在你的JavaScript中:
function initIRQ() {
//Begin communication with swf
}