RemoteObjectコンポーネントを介してサービス側からArrayオブジェクトを返す

1236 ワード

1、Java類メソッドソースコード
public User[] usersArray(){
	User[] users = new User[3];
	
	User u1 = new User("uid1", "pwd1");
	User u2 = new User("uid2", "pwd2");
	User u3 = new User("uid3", "pwd3");
	
	users[0] = u1;
	users[1] = u2;
	users[2] = u3;
	
	return users;
}

 
2、mxmlファイル部分のソースコード
private function call():void{
	var o:Operation = ro.getOperation("usersArray") as Operation;
	o.addEventListener(ResultEvent.RESULT, resultEvent);
	o.send();
}

private function resultEvent(event:ResultEvent):void{ 
	try{
		var s:String = "";
		
		//Java List       AS Array  
		var arr:Array = event.result as Array;
		
		//  ComboBox       
		combo1.dataProvider = arr;
		
		//    Array         ,     User
		for(var i:int=0;i<arr.length;i++){
			var u:User = arr[i] as User;
			s += u.username + ", " + u.password + "
"; } txt1.text = s; }catch(e:Error){ txt1.text = e.message; } }