加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex3与BlazeDS HelloWorld 详解

发布时间:2020-12-15 04:29:25 所属栏目:百科 来源:网络整理
导读:BlazeDS的下载和介绍: http://opensource.adobe.com/wiki/display/blazeds/Release+Builds ? 有Tomcat的下载? http://flexorg.wip3.adobe.com/blazeds/3.0.x/milestone/3978/blazeds-bin-3.2.0.3978.zip 没Tomcat的下载? http://flexorg.wip3.adobe.com/bla

BlazeDS的下载和介绍:
http://opensource.adobe.com/wiki/display/blazeds/Release+Builds?
有Tomcat的下载?
http://flexorg.wip3.adobe.com/blazeds/3.0.x/milestone/3978/blazeds-bin-3.2.0.3978.zip
没Tomcat的下载?
http://flexorg.wip3.adobe.com/blazeds/3.0.x/milestone/3978/blazeds-turnkey-3.2.0.3978.zip

下载后将blazeds.war部署到tomcat下即可。

Flex Builder插件的安装不再作介绍

开发工作为MyEclipse:

1.新建一个Flex工程

按照图中进行配置
2.下一步:

指定已经下载的blazeds.war
3.下一步.

配置url
4.完成后右键配置工程属性:

注意context的修改,不然运行程序会报404.

5.新建一个测试类:

[html]? view plain copy
  1. package?com;??
  2. ??
  3. public?class?HelloWorld??
  4. {??
  5. ????public?String?say(String?username)??
  6. ????{??
  7. ????????System.out.println("hello");??
  8. ????????return?"你好!"?+?username;??
  9. ????}??
  10. ??????
  11. ????public?String?login(String?username,String?password)??
  12. ????????System.out.println("login");??
  13. ????????if(username.equals("admin")?&&?password.equals("admin"))??
  14. ????????{??
  15. ????????????return?"success";??
  16. ????????}??
  17. ????????else??
  18. ????????????return?"failure";??
  19. ????}??
  20. }??


6.配置web-inf/flex 下的remoting-config.xml文件:

copy
    <?xml?version="1.0"?encoding="UTF-8"?>??
  1. <service?id="remoting-service"???
  2. ????class="flex.messaging.services.RemotingService">??
  3. ????adapters ????????adapter-definition?id="java-object"?class="flex.messaging.services.remoting.adapters.JavaAdapter"?default="true"/>??
  4. </default-channelschannel?ref="my-amf" ????<!--?目标java类?-->??
  5. destination?id="helloworld"properties>??
  6. ????????????source>com.HelloWorlddestination>??????
  7. service>??

7.编写mxml文件:

copy
    xml?version="1.0"?encoding="utf-8"mx:Application?xmlns:mx="http://www.adobe.com/2006/mxml"?layout="absolute" ??
  1. mx:Script ????<![CDATA[?
  2. ????????import?mx.rpc.events.ResultEvent;?
  3. ????????import?mx.controls.Alert;?
  4. ????????//hello事件?
  5. ????????private?function?helloClick():void?
  6. ????????{?
  7. ????????????this.hello.say(this.username.text);?
  8. ????????}?
  9. ?????????
  10. ????????//登录事件??
  11. ????????private?function?loginClick():void?
  12. ????????????this.login.login(this.username.text,this.password.text);?
  13. ????????//处理hello事件?返回值?
  14. ????????private?function?resultHandler(e:ResultEvent):void?
  15. ????????{?
  16. ????????????Alert.show(e.result.toString());?
  17. ????????}?
  18. ????????//处理登录事件返回值?
  19. ????????private?function?resultLoginHandler(e:ResultEvent):void?
  20. ????????????Alert.show(e.result?as?String);?
  21. ????]]>??
  22. ????<!--远程对象调用-->??
  23. mx:RemoteObject?id="hello"?destination="helloworld"?result="resultHandler(event)"?/>??????
  24. mx:RemoteObject?id="login"?destination="helloworld"?result="resultLoginHandler(event)"?/>??????????
  25. mx:TextInput?id="username"?x="187"?y="99"?width="119"/>??
  26. ????mx:Label?x="123"?y="101"?text="username:"mx:Label?x="123"?y="141"?text="password:"mx:TextInput?id="password"?x="187"?y="139"?width="119"? ??????
  27. mx:Button?x="241"?y="184"?label="Login"?click="loginClick()"mx:Button?x="123"?y="184"?label="HelloWorld"?click="helloClick()"mx:Application>??


7.找到bin-debug下的secondBlaze.html右键选择在Run on Server即可。


?效效果图
源码下载

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读