zoukankan      html  css  js  c++  java
  • flex与java通信的小例子

    很简单的小例子,适合初学者理解

    1,JavaFlex.java

    1. package flex;  
    2.   
    3. public class JavaFlex {  
    4.     public String helloJavaFlex(String name) {  
    5.         return name;  
    6.     }  
    7. }  

    2,remoting-config.xml

    1. <?xml version="1.0" encoding="UTF-8"?>  
    2. <service id="remoting-service" class="flex.messaging.services.RemotingService">  
    3.   
    4.     <adapters>  
    5.         <adapter-definition id="java-object"  
    6.             class="flex.messaging.services.remoting.adapters.JavaAdapter"  
    7.             default="true" />  
    8.     </adapters>  
    9.   
    10.     <default-channels>  
    11.         <channel ref="my-amf" />  
    12.     </default-channels>  
    13.     <destination id="firstJavaFlex">  
    14.         <properties>  
    15.             <source>flex.JavaFlex  
    16.             </source>  
    17.         </properties>  
    18.     </destination>  
    19. </service>  

    3,testflex.mxml

    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"   
    3.                xmlns:s="library://ns.adobe.com/flex/spark"   
    4.                xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">  
    5.     <fx:Declarations>  
    6.         <!-- 将 非可视元素(例如服务、值对象)放在此处 -->  
    7.         <s:RemoteObject id="selectHello" destination="firstJavaFlex" fault="error(event)"/>  
    8.     </fx:Declarations>  
    9.     <fx:Script>  
    10.         <!--[CDATA[  
    11.             import mx.collections.ArrayCollection;  
    12.             import mx.controls.Alert;  
    13.             import mx.events.ResizeEvent;  
    14.             import mx.rpc.events.FaultEvent;  
    15.             import mx.rpc.events.ResultEvent;  
    16.               
    17.             [Bindable]  
    18.             private var arraylist:ArrayCollection = new ArrayCollection([  
    19.                 {name:"你好",data:"你好!"},  
    20.                 {name:"你们好",data:"你们 好!"},  
    21.                 {name:"大家好",data:"大家 好!"},  
    22.             ]);  
    23.             private function changehandler(event:Event):void{  
    24.                 selectHello.helloJavaFlex(selected.selectedItem.data);  
    25.                 selectHello.addEventListener(ResultEvent.RESULT,remoteResult);  
    26.             }  
    27.             private function remoteResult(event:ResultEvent):void{  
    28.                 Alert.show(event.result.toString());  
    29.                 resultmess.text = event.result.toString();  
    30.             }  
    31.             private function error(event:FaultEvent):void{  
    32.                 Alert.show(event.message.body.toString());  
    33.                 resultmess.text = event.message.body.toString();  
    34.             }  
    35.         ]]-->  
    36.     </fx:Script>  
    37.     <s:DropDownList x="113" y="83" id="selected" labelField="name" dataProvider="{arraylist}" change="changehandler(event)"/>  
    38.     <s:RichText x="321" y="227" id="resultmess" text="RichText"/>  
    39. </s:Application>  

    源码下载

  • 相关阅读:
    windwos8.1英文版安装SQL2008 R2中断停止的解决方案
    indwows8.1 英文版64位安装数据库时出现The ENU localization is not supported by this SQL Server media
    Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds
    SQL数据附加问题
    eclipse,myeclipse中集合svn的方法
    JAVA SSH 框架介绍
    SSH框架-相关知识点
    SuperMapRealSpace Heading Tilt Roll的理解
    SuperMap iserver manage不能访问本地目的(IE9)
    Myeclipse中js文件中的乱码处理
  • 原文地址:https://www.cnblogs.com/nianshi/p/1732447.html
Copyright © 2011-2022 走看看