flex与普通java类通信RemoteObject;
flex与服务器交互HTTPService;
flex与webservice交互WebService。
当大家尝试使用flex与普通java类通信时,一般用RemoteObject,具体的代码段如下:
package com.flex.demo;
/** *第一种 功能描述:该类用来实现flex与普通java类中的方法通信 * @author Administrator */ //以上是打头的功能描述,可以不写。 <!--flex 与普通java类通信--> <s:RemoteObject id=“serv“ destination=“myservice“ fault=“serv_faultHandler(event)“ result=“serv_resultHandler(event)“> <properties> <source>com.flex.demo.SimpleService</source> </properties> </s:RemoteObject> [js] view plaincopy <!--flex 与服务器交互HTTPService--> <!--servlet代码--> /** * 第二种 功能描述:该servlet用来与flex进行交互 * @author Administrator */ @SuppressWarnings(“serial“) public class SimpleServiceServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding(“utf-8“); response.setCharacterEncoding(“utf-8“); response.getWriter().write(“我是服务器“); } } |
flex与服务器交互HTTPService,flex端代码
<!-- flex 与服务器交互--> <s:HTTPService id=“service“ fault=“service_faultHandler(event)“ result=“service_resultHandler(event)“ url=“http://localhost:8080/flexdemo/simpleServiceServlet“> </s:HTTPService> <!--第三种 flex与webservice交互WebService--> <!--flex与webservice交互这里调用一个天气预报的webservice--> <s:WebService id=“ws“ wsdl=“http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl“ fault=“ws_faultHandler(event)“ result=“ws_resultHandler(event)“ showBusyCursor=“true“> <!-- 调用webservice的方法<speration>--> |
另外,我想说一下的是,对于弹出框的代码段虽然是很简单的,但是也最好不要漏掉:
protected function service_faultHandler(event:FaultEvent):void{ Alert.show(“调用失败了:“+event.fault.message as String,“提示“); } protected function service_resultHandler(event:ResultEvent):void{ Alert.show(“调用成功了:“+event.result as String,“提示“); } <span style="font-family:Arial; background-color:#ffffff"></span> |