一个remoteobject调用多个java方法(Flex)
1 定义remoteobject对象
1 <fx:Declarations> 2 <s:RemoteObject id="myService" destination="demoservice" 3 endpoint="http://localhost:8080/BlazeJavaDemo/messagebroker/amf" 4 fault="myService_faultHandler(event)" 5 showBusyCursor="true" > 6 <s:method name="returnMapPoint" result="createPoint(event);"/> 7 <s:method name="returnWHPoint" result="createWHPoint(event);"/> 8 </s:RemoteObject> 9 10 </fx:Declarations>
2 编辑各方法的回调函数
1 <fx:Script> 2 <![CDATA[ 3 //回调失败时调用的函数 4 protected function myService_faultHandler(event:FaultEvent):void 5 { 6 Alert.show(event.fault.message); 7 } 8 9 public function createPoint(event:ResultEvent):void{ 10 var javaList:ArrayCollection = ArrayCollection(event.result); 11 trace(javaList.length); 12 13 // myLayer.clear(); 14 for(var i:int=0;i<javaList.length;i++){ 15 var temp:MPoint = MPoint(javaList.getItemAt(i)); 16 var mapPoint:MapPoint = new MapPoint(Number(temp.xString),Number(temp.yString),new SpatialReference(4326)); 17 trace("x:"+Number(temp.xString)); 18 19 var grahpic:Graphic=new Graphic(mapPoint,sps); 20 21 myLayer.add(grahpic); 22 } 23 } 24 25 public function createWHPoint(event:ResultEvent):void{ 26 var javaList:ArrayCollection = ArrayCollection(event.result); 27 // myLayer.clear(); 28 for(var i:int=0;i<javaList.length;i++){ 29 var temp:MPoint = MPoint(javaList.getItemAt(i)); 30 var mapPoint:MapPoint = new MapPoint(Number(temp.xString),Number(temp.yString),new SpatialReference(4326)); 31 32 var grahpic:Graphic=new Graphic(mapPoint,defaultSymbol); 33 grahpic.attributes = {"xValue":temp.xString,"yValue":temp.yString}; 34 35 grahpic.addEventListener(MouseEvent.ROLL_OVER,maouseOverHandler); 36 grahpic.addEventListener(MouseEvent.ROLL_OUT,maouseOutHandler); 37 38 myLayer.add(grahpic); 39 } 40 } 41 42 43 ]]> 44 </fx:Script>
3 调用
1 <s:HGroup> 2 <s:Button label="描点(沈阳)" click="myService.returnMapPoint.send()" /> 3 <s:Button label="描点(武汉)" click="myService.returnWHPoint.send()" /> 4 </s:HGroup>