Actionscript 3 AS3本地连接错误
我不确定我会错在哪里,现在只是在本地尝试一下。谢谢 sendingLC.swf不返回,LocalConnection.send()成功 这是我从Flash中得到的错误。 错误#2044:未处理的AsyncErrorEvent:。text=错误#2095:flash.net.LocalConnection无法调用回调方法。error=ReferenceError:error#1069:在flash.net.LocalConnection上找不到属性myMethod,并且没有默认值 发送lc.swf的代码:Actionscript 3 AS3本地连接错误,actionscript-3,localconnection,Actionscript 3,Localconnection,我不确定我会错在哪里,现在只是在本地尝试一下。谢谢 sendingLC.swf不返回,LocalConnection.send()成功 这是我从Flash中得到的错误。 错误#2044:未处理的AsyncErrorEvent:。text=错误#2095:flash.net.LocalConnection无法调用回调方法。error=ReferenceError:error#1069:在flash.net.LocalConnection上找不到属性myMethod,并且没有默认值 发送lc.swf
import flash.net.LocalConnection
var sendingLC:LocalConnection;
sendingLC = new LocalConnection();
sendingLC.allowDomain('*');
Security.allowDomain("*");
sendBtn.addEventListener(MouseEvent.CLICK, sendIt);
function sendIt(eventObj:MouseEvent):void {
sendingLC.send('myConnection', 'myMethod');
}
sendingLC.addEventListener(StatusEvent.STATUS, statusHandler);
function statusHandler (event:StatusEvent):void
{
switch (event.level)
{
case "status" :
textArea.text = ("LocalConnection.send() succeeded");
break;
case "error" :
textArea.text = ("LocalConnection.send() failed");
break;
}
}
import flash.net.LocalConnection
var receivingLC:LocalConnection;
receivingLC = new LocalConnection();
receivingLC.allowDomain('*');
Security.allowDomain("*");
receivingLC.connect('myConnection');
function myMethod():void {trace('Hello World')}
接收LC.swf的代码:
import flash.net.LocalConnection
var sendingLC:LocalConnection;
sendingLC = new LocalConnection();
sendingLC.allowDomain('*');
Security.allowDomain("*");
sendBtn.addEventListener(MouseEvent.CLICK, sendIt);
function sendIt(eventObj:MouseEvent):void {
sendingLC.send('myConnection', 'myMethod');
}
sendingLC.addEventListener(StatusEvent.STATUS, statusHandler);
function statusHandler (event:StatusEvent):void
{
switch (event.level)
{
case "status" :
textArea.text = ("LocalConnection.send() succeeded");
break;
case "error" :
textArea.text = ("LocalConnection.send() failed");
break;
}
}
import flash.net.LocalConnection
var receivingLC:LocalConnection;
receivingLC = new LocalConnection();
receivingLC.allowDomain('*');
Security.allowDomain("*");
receivingLC.connect('myConnection');
function myMethod():void {trace('Hello World')}
也许可以试着像这样公开
myMethod
:
public function myMethod():void{
trace("hello world");
}
此外,您还应尝试/捕获发送呼叫,以便获得有关错误的更多信息,例如:
try{
sendingLC.send('myConnection', 'myMethod');
}
catch(e:Error){
trace(e.toString());
}
在接收器中建立连接可能存在问题
try {
var receivingLC:LocalConnection;
receivingLC = new LocalConnection();
receivingLC.allowDomain('*');
Security.allowDomain("*"); // not sure this line is needed
receivingLC.connect('myConnection');
} catch (error:ArgumentError) {
trace('failure to make connection ' + error.toString() );
}
另外需要注意的是,不要在flash api中测试LocalConnections,当您第一次进行这些操作时,请通过浏览器进行操作,因为权限问题可能是一个脾气暴躁的女人。我也遇到了LocalConnection的问题,它会给我回叫错误,但当我将客户端属性添加到连接时,它停止了。然后它开始工作,甚至在flashide中也是如此
var conn:LocalConnection;
conn = new LocalConnection();
conn.allowDomain('*');
conn.client = this;
conn.connect('localThingieConnector');
我按您的方式尝试了try/catch,但得到了1046:Type未找到或不是编译时常量:Exception。我以前没有用过try/catch,所以我得进一步研究一下。ThanksAt您调用sendIt函数的目的是什么?当时两个swf都加载了吗?我打开两个swf,然后单击sendBtn,它调用Sendit它们在浏览器中打开了吗?所以我终于有时间尝试一下你的建议,我现在在浏览器中进行测试,在最终实现中,每个swf都将在单独的iFrame中,所以这就是我测试的方式。我仍然会得到与本地测试时相同的错误,没有额外的输出。Thankstry sendingLC.send(“U myConnection”,“myMethod”);和接收lc.connect(“u myConnection”);下划线确实有意义