加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在flex中动态实现RemoteObject

发布时间:2020-12-15 05:15:07 所属栏目:百科 来源:网络整理
导读:?在flex中,一般直接在设计时写remoteobject的话,这个是比较普遍了,但有的时候,需要在AS代码中动态设置 remoteobject,这个比较少见,所以小结学习之: ?? 情景是,当页面加载时,代码新建立一个remoteobject,然后设置其方法和调用参数,最后把调用返回的

?在flex中,一般直接在设计时写remoteobject的话,这个是比较普遍了,但有的时候,需要在AS代码中动态设置

remoteobject,这个比较少见,所以小结学习之:

?? 情景是,当页面加载时,代码新建立一个remoteobject,然后设置其方法和调用参数,最后把调用返回的结果(是JAVA中的一个LIST),绑定到

一个repeater控件中去,下面来看代码:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="firstload()" width="706" height="417">

?

? [Bindable]????
??????????? private var posArray:ArrayCollection = new ArrayCollection();????
???
???private function firstload():void
???{
????var categoryremote:RemoteObject=new RemoteObject();???
?????categoryremote.destination="categoryservice";
???var o:AbstractOperation = categoryremote.getOperation("getCategoriesByPidflex");????
???? o.send(144);???
? o.addEventListener(ResultEvent.RESULT,resultEvent);???
???}

//remoteobject返回的list
???private function resultEvent(event:ResultEvent):void{??
????
???? posArray = event.result as ArrayCollection;
????r.dataProvider=posArray;
????
???}
???private function findAllFaultHandler(event:FaultEvent):void?
???{
????Alert.show(event.fault.faultString,"Error");
???}

? 注意用o.send中,包含了要发送的参数,? o.addEventListener(ResultEvent.RESULT,resultEvent)中,处理返回的结果事件。

?<mx:Repeater id="r">
???????
?????????????????? <mx:Button id="repbutton" label="{Category(r.currentItem).name}" click="var btn:Button = Button(event.currentTarget);Alert.show(Category(btn.getRepeaterItem()).id); " width="555" height="83" textAlign="center" fontSize="27"/>
</mx:Repeater>

这里注意repeater R的dataprovider是动态设置的,在代码中,并且当点repeater中的每个按钮时,取得了所点选的button的id编号(注意这里因为列出的是一个个

category类,所以要先转型为Category,然后再获得其id

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读