如何将类型化对象从 FMS 发送到客户端

发布于 2024-08-16 18:42:20 字数 675 浏览 3 评论 0原文

我在FMS中有以下对象

User = function(userName,userId)

{

this.userName = userName;

this.userId = 用户Id;

需要将用户列表发送到客户端 swf。一旦我将 User 对象集合初始化为数组,当我从客户端读取数组元素时,数组元素是未定义的。

但是我也无法发送通用对象。一旦我初始化了对象中的数组元素,如下所示。它还在客户端给出了未定义的信息。

var myObj = {userName:"user1name", userId:"user1id"};

但以下工作

var arr2 = [];

arr2["用户名"] = "用户名1"; arr2["用户ID"] = "用户1ID";

客户端连接到 FMS 上的主应用程序。然后它通过 NetConnection 连接到第二个应用程序。我已经使用“registerProxy”功能映射了远程方法。

例如:application.registerProxy(localName,this._nc,remoteName);

以上描述了第二应用中的方法。我在客户端使用 Actionscript 2。

任何解决该问题的方案都受到高度赞赏。

提前致谢。

I have following object in the FMS

User = function(userName,userId)

{

this.userName = userName;

this.userId = userId;

}

I need to send the list of user to the client swf. Once I initialized the User object collection to an array, array element is undefined when I read it from the client.

However I can’t send the generic object too. Once I initialized the array elements in Objects as follow. It also give the undefined in the client side.

var myObj = {userName:"user1name", userId:"user1id"};

But following works

var arr2 = [];

arr2["userName"] = "user1name ";
arr2["userId "] = " user1id";

Clients are connected to the main application on the FMS. Then it connect to second application through NetConnection. And I have mapped the remote method using the ‘registerProxy’ feature.

Eg: application.registerProxy(localName,this._nc,remoteName);

Above described method in the second application. I’m using Actionscript 2 for client side.

Any solution for the matter is highly appreciated.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弥枳 2024-08-23 18:42:20

据我所知,没有办法将客户端类映射到服务器端FMS类。据我所知,在 AS2 中,这个功能根本不存在。

我已经用 AS3 尝试过你的例子。传递对象(尽管无类型)适用于 FMS 3.5。

客户端:

private var nc:NetConnection;
private function init():void  {
    nc = new NetConnection();
    nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
    nc.connect("rtmp:/test");
}
private function netStatusHandler(event:NetStatusEvent):void {
    trace(event.info.code);
    if(event.info.code == "NetConnection.Connect.Success") {
        var responder:Responder = new Responder(resultHandler);
        nc.call("getUser", responder, "hrundik", 1234);
    }
}
private function resultHandler(result:Object):void {
    if(result)
        trace(result.userName, result.userId);
}

服务器端:

User = function(userName,userId) {
    this.userName = userName;
    this.userId = userId;
}
application.onConnect = function (client) {
    trace("client connected!");
    client.getUser = function(userName, userId) {
        return new User(userName, userId);
    }
    return true;
}

AS2 和 AS3 之间差异的原因可能在于所使用的对象编码协议 - AMF0 与 AMF3。尽管如此,AMF0 在 AS3 中按预期工作。

因此,也许可以考虑将您的应用程序移植到 AS3。

As far as I know, there is no way to map client-side classes to server-side FMS classes. In AS2 this functionality was simply absent, as far as I remember the old times.

I've tried your example with AS3. Passing objects (though untyped) works with FMS 3.5.

Client-side:

private var nc:NetConnection;
private function init():void  {
    nc = new NetConnection();
    nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
    nc.connect("rtmp:/test");
}
private function netStatusHandler(event:NetStatusEvent):void {
    trace(event.info.code);
    if(event.info.code == "NetConnection.Connect.Success") {
        var responder:Responder = new Responder(resultHandler);
        nc.call("getUser", responder, "hrundik", 1234);
    }
}
private function resultHandler(result:Object):void {
    if(result)
        trace(result.userName, result.userId);
}

Server-side:

User = function(userName,userId) {
    this.userName = userName;
    this.userId = userId;
}
application.onConnect = function (client) {
    trace("client connected!");
    client.getUser = function(userName, userId) {
        return new User(userName, userId);
    }
    return true;
}

The reason in differences between AS2 and AS3 might be in object encoding protocol being used - AMF0 vs AMF3. Although, AMF0 works as expected in AS3.

So, perhaps, consider porting your application to AS3.

三生一梦 2024-08-23 18:42:20

谢谢,但是您给了我很好的提示:) FMS 服务器上的内部应用程序 NetConnection 出现问题。默认情况下,FMS 3 使用 AMF3 序列化。自从我的客户端应用程序 AS2 以来,我更改了 FMS 上的 ObjectEncoding Application.xml,

例如。 AMF0

Thanks, However you gave me good hint :) Problem in the inter application NetConnection on the FMS Server. By default FMS 3 uses the AMF3 serialization. Since my client application AS2, I have change the the ObjectEncoding Application.xml on FMS

eg. <ObjectEncoding>AMF0</ObjectEncoding>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文