ActionScript Object 到Java Object 的映射 ActionScript Object to the Java Object Mapping

以前用Flex开发程序的时候,还真的没有用到将ActionScript Object 映射到Java Object,一般都是从后台读数据到前台,做的都是JAVA 到AS 的数据映射。 Before using Flex development process, really did not use the maps to be ActionScript Object Java Object, are generally read data from the background to the future, to do all JAVA AS data mapping. 今天做毕业设计上传数据的时候遇到了问题,如下: Today, graduated from design to upload the data when the encounter a problem, as follows:

我有一个Group对象,里面有几个字段(groupID,groupName),本来我是要上传一个Group对象数组的,而AS3的数组映射到JAVA中是java.util.List 对象,不管你在AS3 中是什么对象数组,在JAVA中都变成了原始的Object,我在JAVA 端取出一个Object,试图用.groupID访问它的字段,首先Eclipse告诉我没有这个字段,程序有错误。 I have a Group object, there are several fields (groupID, groupName), I had to upload a Group array of targets, and AS3 the array is mapped to the JAVA java.util.List object, whether you in AS3 What is the object of the array, in the JAVA have become the original Object, I retrieve a JAVA-Object, trying to use. GroupID visit to the field, the first Eclipse did not tell me this field, procedures are wrong. 不管它,强行编译,结果告诉我无法识别! Whether it forced compiler, told me not recognize the results! 这种情况在AS3中不会出现,因为如果是一个Object,AS3就会默认它可能拥有任何字段,FB 也不会提示错误。 This situation will not arise in AS3, because if a Object, AS3 will default it may be in possession of any field, FB will not prompt error.

怎么办呢? How do » 我去翻BlazeDS的文档,终于找到了答案。 I Qufan BlazeDS the document, finally found the answer. 原来可以在AS中强行将某个类映射到JAVA的某个类,这样在与JAVA端交换数据的时候就自动将AS3 中的某个类映射为相应的类。 AS the original can be a force in the category JAVA mapped to a certain category, and this in JAVA-time exchange of data automatically will AS3 in a category mapping for the corresponding category. 比如我在JAVA 中也有一个Group 类,有一个方法upload(Group[] groups), 做了强制映射之后,我就可以在AS中直接调用upload 方法并将AS 中的Group 数组作为参数,这样在JAVA端就可以直接读取了。 For example, I also have a JAVA Group category, there is a way upload (Group [] groups), done a mandatory mapping, I can call directly upload AS methods and AS Group in the array as a parameter, so that JAVA client can direct the reader. 当然,你得保证两个类的字段相同。 Of course, you have to ensure that the two categories of the same field.

强制映射就要使用[RemoteClass(alias=" ")] 这个元数据标签,用法如下: Mapping will be forced to use [RemoteClass (alias = "")] of this meta-data tags, usage is as follows:

package samples.contact { package samples.contact (
[Bindable]
[RemoteClass(alias="samples.contact.Contact")] [RemoteClass (alias = "samples.contact.Contact")]
public class Contact { public class Contact (
………….. ………… ..
……
} )

其中samples.contact.Contact 是JAVA 端的相应类。 Samples.contact.Contact JAVA-which is the corresponding category.



本文链接: http://www.zhuoqun.net/html/y2008/995.html 转载请注明出处,谢谢。 This link: http://www.zhuoqun.net/html/y2008/995.html reprint please reference, thank you.

TrackBack引用地址: http://www.zhuoqun.net/html/y2008/995.html/trackback TrackBack used Address: http://www.zhuoqun.net/html/y2008/995.html/trackback

相关日志 Related Log


Posted in Flex , 技术 . Posted in Flex, technology.

3条评论 3 reviews

  • At 2008.04.19 17:22, 百奥谷 said: At 2008.04.19 17:22, 100 Okudani said:

    边看边学 Watch learning

    • At 2008.04.25 13:30, zl said: At 2008.04.25 13:30, zl said:

      其实你菜的不行 In fact, the dishes you not

    (Required) (Required)
    (Required, will not be published) (Required, will not be published)
    关闭 Close
    Powered by ShareThis