AS3 LocalConnection错误

时间:2011-07-26 18:05:29

标签: actionscript-3 localconnection

不知道我哪里出错了,现在只是在本地尝试一下。感谢。

发送LC.swf确实返回,LocalConnection.send()成功

这是我从Flash获得的错误。 错误#2044:未处理的AsyncErrorEvent:。 text =错误#2095:flash.net.LocalConnection无法调用回调myMethod。 error = ReferenceError:错误#1069:在flash.net.LocalConnection上找不到属性myMethod,并且没有默认值。

sendLC.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;
    }
}

接收LC.swf的代码:

import flash.net.LocalConnection

var receivingLC:LocalConnection;
receivingLC = new LocalConnection();
receivingLC.allowDomain('*');
Security.allowDomain("*");
receivingLC.connect('myConnection');

function myMethod():void {trace('Hello World')}

3 个答案:

答案 0 :(得分:2)

我也遇到了LocalConnection问题,给了我回调错误,但是当我将客户端属性添加到连接时它停止了。然后它开始工作,甚至在flash IDE中。

var conn:LocalConnection;
conn = new LocalConnection();
conn.allowDomain('*');
conn.client = this;
conn.connect('localThingieConnector');

答案 1 :(得分:0)

或许尝试将myMethod公之于众:

public function myMethod():void{
  trace("hello world");
}

此外,您应该尝试/捕获发送呼叫,以便获得有关错误的更多信息,如下所示:

try{
  sendingLC.send('myConnection', 'myMethod');
}
catch(e:Error){
  trace(e.toString());
}

答案 2 :(得分:0)

在接收器中建立连接可能存在问题。

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,因为权限问题可能是一个胡思乱想的女人。