[RemoteClass] 如何在 Flex Actionscript 中工作 我可以将它用于自定义数据绑定吗? [英] How does [RemoteClass] work in Flex Actionscript can I use it for custom data-binding?

查看:24
本文介绍了[RemoteClass] 如何在 Flex Actionscript 中工作 我可以将它用于自定义数据绑定吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Actionscript 支持在 BlazeDS 中使用的 [RemoteClass] 元数据标签,为将 AMF 二进制对象从 Java 编组到 BlazeDS 提供数据绑定提示.

Actionscript supports a [RemoteClass] metadata tag that is used in BlazeDS to provide data-binding hints for marshalling AMF binary objects from Java to BlazeDS.

例如:

Java:包装样品;

public class UserInfo
{
    private String userName;

    public String getUserName()
    {
        return userName;
    }

    public void setUserName(String value)
    {
        userName = value;
    }
}

动作脚本:

[Bindable]
[RemoteClass(alias="sample.UserInfo")]
public class UserInfo
{
    public var userName:String="";
}

[RemoteClass] 是如何在 BlazeDS 框架中实现的,您能否覆盖该行为并提供可以绑定到 Actionscript [Bindable] 的自定义数据绑定远程处理框架(例如 JSON 消息传递系统),[RemoteClass] 类?

How exactly is the [RemoteClass] implemented in the BlazeDS framework and could you override that behavior and provide a custom data-binding remoting framework (e.g. a JSON message passing system) that you could bind to the Actionscript [Bindable], [RemoteClass] class?

推荐答案

[RemoteClass(alias="com.example.MyClass")] 是调用 flash.net.registerClassAlias() :

[RemoteClass(alias="com.example.MyClass")] is a Flex shorthand for calling flash.net.registerClassAlias() :

public function registerClassAlias(aliasName:String, classObject:Class):void

要在运行时访问那些注册的别名类(编写自定义 JSON 数据序列化框架),您可以调用:

To access those registered alias classes at runtime (to write a custom JSON data serialization framework) you can call:

getClassByAlias(别名:字符串):类通过调用 registerClassAlias() 方法查找以前注册了别名的类.

getClassByAlias(aliasName:String):Class Looks up a class that previously had an alias registered through a call to the registerClassAlias() method.

对于从 AS 到 Java 的传出编码,您需要检索别名类名,您可以通过调用 flash.utils.describeType() 并在 Actionscript 对象的类上使用反射"来查询对象的属性、属性和方法.

For outgoing encoding from AS to Java you need to retrieve the aliased class name, you can do that by calling flash.utils.describeType() and use "reflection" on your Actionscript object's class to query attributes, properties, methods of the object.

例如以下代码片段 ObjectCodec.as 似乎使用@"检索别名属性:

For example the following code snippet for ObjectCodec.as seems to retrieve the alias attribute by using "@":

override protected function encodeComplex(o:Object, b:IBinary, context:IContext=null):void
{
        var desc:XML = describeType(o);
        var classAlias:String = desc.@alias;
        //...
}

这篇关于[RemoteClass] 如何在 Flex Actionscript 中工作 我可以将它用于自定义数据绑定吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆