RemoteObjectコンポーネントを介してサービス側からListオブジェクトを返す
1、Java類メソッドソースコード
2、mxmlファイルのソースコード
public List listUsers(){
List list = new ArrayList();
User u1 = new User("uid1", "pwd1");
User u2 = new User("uid2", "pwd2");
User u3 = new User("uid3", "pwd3");
list.add(u1);
list.add(u2);
list.add(u3);
return list;
}
2、mxmlファイルのソースコード
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
<mx:Script>
<![CDATA[
private function call():void{
var o:Operation = ro.getOperation("listUsers") as Operation;
o.addEventListener(ResultEvent.RESULT, resultEvent);
o.send();
}
private function resultEvent(event:ResultEvent):void{
try{
var s:String = "";
//Java List AS ArrayCollection
var list:ArrayCollection = event.result as ArrayCollection;
// ComboBox
combo1.dataProvider = list;
// ArrayCollection , User
for(var i:int=0;i<list.length;i++){
var u:User = list.getItemAt(i) as User;
s += u.username + ", " + u.password + "
";
}
txt1.text = s;
}catch(e:Error){
txt1.text = e.message;
}
}
private function closeHandler(event:Event){
var c:ComboBox = event.target as ComboBox;
var s:String = c.selectedItem.username + ", " + c.selectedItem.password;
Alert.show(s);
}
]]>
</mx:Script>
<mx:RemoteObject id="ro" destination="remoteService" fault="faultEvent(event)"/>
<mx:Button x="27" y="28" label="Load" click="call()"/>
<mx:TextArea x="27" y="58" width="450" height="143" id="txt1"/>
<mx:ComboBox x="27" y="209" id="combo1" labelField="username" close="closeHandler(event)"/>
</mx:Application>