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

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

问题描述

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



例如:



Java:
包样本;

 code> public class UserInfo 
{
private String userName;

public String getUserName()
{
return userName;
}

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

Actionscript: p>

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

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

解决方案

[RemoteClass(alias =com.example.MyClass)]是一个Flex简写,用于调用 flash.net.registerClassAlias()

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

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



getClassByAlias (aliasName:String):Class
查找以前通过一个别名注册的别名调用registerClassAlias()方法。



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



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

 覆盖保护函数encodeComplex(o:Object,b:IBinary,context:IContext = null):void 
{
var desc:XML = describeType o);
var classAlias:String = desc。@ alias;
// ...
}


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.

For example:

Java: package sample;

public class UserInfo
{
    private String userName;

    public String getUserName()
    {
        return userName;
    }

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

Actionscript:

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

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")] is a Flex shorthand for calling flash.net.registerClassAlias() :

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

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

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

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.

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

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

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