Flex beta2+XFire开发实例 (三)

只谈情不闲聊 提交于 2019-11-27 04:06:01
最后一章

三、编写调用实例


1、设计界面


我是做得比较简单,有一个TextArea用来显示调用结果输出,一个Button用来调用服务的login方法。

2、代码编写

Webs1.mxml

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init(event);">

    <mx:Button x="207" y="192" label="getUserInfo" click="getUserInfo(event);"/>

    <mx:TextArea x="80" y="57" width="223" height="127" id="out"/>

    <mx:Script>

       <![CDATA[

           import symis.business.service.UserManagerService;

           import symis.business.service.User;

           import mx.rpc.events.ResultEvent;

           import mx.rpc.AsyncToken;

           privatevar userManagerService:UserManagerService;

          

           privatefunction init(e:Event):void{

              userManagerService = new UserManagerService();

           }

           privatefunction getUserInfo(e:Event):void{

              var result:AsyncToken =null;

              if(userManagerService!=null)   

                  result =userManagerService.login(100,"hello");

              if(result!=null)

               result.addEventListener("result",function(e:ResultEvent):void{

                  var user:User = e.result as User;

                  out.text = "User Name:="+user.name+""n";

                  out.text +="age :="+user.age;

              });

           }

       ]]>

    </mx:Script>

</mx:Application>

3、运行客户端


a)       初始化webservice

privatefunction init(e:Event):void{

              userManagerService = new UserManagerService();

           }


b)       调用webservice方法

privatefunction getUserInfo(e:Event):void{

              var result:AsyncToken =null;

              if(userManagerService!=null)   

                  result =userManagerService.login(100,"hello");

              if(result!=null)

               result.addEventListener("result",function(e:ResultEvent):void{

                  var user:User = e.result as User;

                  out.text = "User Name:="+user.name+""n";

                  out.text +="age :="+user.age;

              });

           }


四、结束语
抽空写了一些WebService资料,周六晚上也没有好好休息,好长时间没有陪儿子好好玩了,明天还得要开会,希望这些心得能对朋友有些帮助。


转载于:https://www.cnblogs.com/jssy/archive/2007/10/20/931773.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!