同一台计算机上的两个flash应用程序之间传递自定义对象出错(如果myModel中是无参构造函数,则正确)。
出错描述:
Error #2044: 未处理的 AsyncErrorEvent:。 text=Error #2095: flash.net.LocalConnection 无法调用回调 example。 error=ArgumentError: Error #1063: model::MyModel() 的参数数量不匹配。应该有 2 个,当前为 0 个。
很奇怪,不知道在哪出问题了?
源代码:
1、自定义对象:
package model
{
public class MyModel
{
private var _firstName:String;
private var _age:int;
public function MyModel(firstName:String, age:int)
{
//_firstName = firstName;
//_age = age;
}
public function toString():String
{
//return _firstName + "is" + _age + "years old";
return "this is a model"
}
}
}
发送方:
package
{
import flash.display.Sprite;
import flash.net.registerClassAlias;
import flash.net.LocalConnection;
import model.MyModel;
public class Send extends Sprite
{
private var sender:LocalConnection;
public function Send()
{
registerClassAlias("MyModel",MyModel);
var myModel:MyModel = new MyModel("Darron",24);
sender = new LocalConnection();
sender.send("_receive","example",myModel);
}
}
}
接收方:
package
{
import flash.display.Sprite;
import flash.net.registerClassAlias;
import flash.net.LocalConnection;
import model.MyModel;
public class Receive extends Sprite
{
private var receive:LocalConnection;
public function Receive()
{
registerClassAlias("MyModel",MyModel);
receive = new LocalConnection();
receive.connect("_receive");
receive.client = this;
}
public function example(model:MyModel):void
{
trace("this is an example")
}
}
}