Flex Java对象映射

      ResultEvent.result中如果返回的不是java的基本类型则flex会把它转化为Object类型(Object强制转化为As对象后,as对象为null)。如果想让result中的结果自动转化为相应的AS3对象,就需要使用[RemoteClass(alias="完整的java类路径")].

      具体的步骤如下:

      1 定义java bean

public class SecurityAction {

	public String componentId;//组件ID
	public boolean isShow;// 有权限为true 否则为false
	
	/**
	 * 没有权限时的处理方式
	 * 1 remove:通过调用comp.parent.removeChild()完全删除组件
	 * 2 visible:将 compl.visible 属性设置为 false。
	 * 3 enable:将 comp.enable 属性设置为 false。
	 */
	public String showType;

	public String getComponentId() {
		return componentId;
	}

	public void setComponentId(String componentId) {
		this.componentId = componentId;
	}

	public boolean isShow() {
		return isShow;
	}

	public void setShow(boolean isShow) {
		this.isShow = isShow;
	}

	public String getShowType() {
		return showType;
	}

	public void setShowType(String showType) {
		this.showType = showType;
	}

}

 

   2 定as3对象

[Bindable]
	[RemoteClass(alias="com.amc.purview.model.SecurityAction")]
	public class SecurityAction{ 
		public function SecurityAction(){
			
		}
		public var componentId:String;//组件的id
		public var isShow:Boolean;//有权限为true 否则为false
		
		/**
		 * 没有权限时的处理方式
		 * 1 remove:通过调用comp.parent.removeChild()完全删除组件
		 * 2 visible:将 compl.visible 属性设置为 false。
	 	* 3 enable:将 comp.enable 属性设置为 false。
		 */
		public var showType:String;
	} 

 

 3. java端返回结果。

public ArrayCollection getActions(String userId,String pageId){
		ArrayCollection ac=new ArrayCollection();
		SecurityAction action=new SecurityAction();
		action.setComponentId("btn2");
		action.setShow(false);
		action.setShowType("enable");
		ac.add(action);
		return ac;
	}

 

4  flex端处理返回结果。

private function getActionSuc(result:ResultEvent):void{
			var actions:ArrayCollection=result.result as ArrayCollection;
			if(actions!=null){
				Security.load(actions,comp);
			}
		}

 

 

注意:1 as3对象和java对象的属性必须一致,public和private都可以的。

        2 按照规范,暴露给Flex调用的不能包含以下保留的方法名:

 

disconnect()
getOperation()
hasOwnProperty()
initialized()
isPrototypeOf()
logout()
propertyIsEnumerable()
setCredentials()
setPropertyIsEnumerable()
setRemoteCredentials()
toString()
valueOf()

 

如果不小心用到了以上的方法,可以用以下方法解决。

public var myRemoteObject:RemoteObject = new RemoteObject();
myRemoteObject.destination = "ro-catalog";
public var op:Operation = myRemoteObject.getOperation("hasOwnProperty");

 

注意:如果flex中有多个Module,就有可能导致RemoteClass信息丢失,如何解决RemoteClass信息丢失,请参考我的另一篇博客解决RemoteClass alias信息丢失

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值