如何通过 NetConnection 将复杂类型中继到 FMS?
我需要通过 NetConnection 将复杂类型对象(在 Flex 中标记为 RemoteClass)发送到其他客户端。
[RemoteClass]
public class ComplexType
{
public var _someString:String;
public var _someInt:int;
}
...并使用...
_nc = new NetConnection();
_nc.connect("rtmp://localhost/echo/");
_nc.addEventListener(NetStatusEvent.NET_STATUS, _onNetStatus);
_nc.client = {};
_nc.client.echoCallback = _echoCallback;
var dto:ComplexType = new ComplexType();
dto._someInt = 4;
dto._someString = "abrakadabra";
_nc.call("echo", null, dto);
但是,服务器端的回调函数似乎不理解强类型对象并发送回以下内容:
private function _echoCallback(...args):void
{
trace(ObjectUtil.toString(args));
/*
(Array)#0
[0] (Object)#1
_someInt = 4
_someString = "abrakadabra"
*/
}
服务器端看起来像这样:
application.onAppStart = function () {
trace("Application.onAppStart > application started");
Client.prototype.echo = function (complexType /*ComplexType*/) {
trace("Client.echo > calling echo");
application.broadcastMsg("echoCallback", complexType);
}
}
有没有办法通过 NetConnection 中继强类型对象?
EDIT1:添加带有 ObjectUtil.toString() 输出的回调函数源代码
I need to send complex type object (marked RemoteClass in Flex) via NetConnection to other clients.
[RemoteClass]
public class ComplexType
{
public var _someString:String;
public var _someInt:int;
}
... and using ...
_nc = new NetConnection();
_nc.connect("rtmp://localhost/echo/");
_nc.addEventListener(NetStatusEvent.NET_STATUS, _onNetStatus);
_nc.client = {};
_nc.client.echoCallback = _echoCallback;
var dto:ComplexType = new ComplexType();
dto._someInt = 4;
dto._someString = "abrakadabra";
_nc.call("echo", null, dto);
However it seems, that callback function on server side don't understand strongly typed objects and sends back this:
private function _echoCallback(...args):void
{
trace(ObjectUtil.toString(args));
/*
(Array)#0
[0] (Object)#1
_someInt = 4
_someString = "abrakadabra"
*/
}
Server side looks like this:
application.onAppStart = function () {
trace("Application.onAppStart > application started");
Client.prototype.echo = function (complexType /*ComplexType*/) {
trace("Client.echo > calling echo");
application.broadcastMsg("echoCallback", complexType);
}
}
Is there a way to relay strongly typed object via NetConnection?
EDIT1: added callback function source code with ObjectUtil.toString() output
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将
alias
属性添加到[RemoteClass]
注释中:这应该将匿名对象更改为 AMF 中的类型化对象。
You need to add an
alias
property to your[RemoteClass]
annotation:This should change the anonymous object to a typed object in AMF.
用于发送用途:
用于接收:
太棒了!!!!
For sending use:
And for receiving:
It woooorks!!!!