renxiao2003 发表于 2011-12-21 08:44

用一个HelloWorl例子手把手教会你使用BlazeDS

<DIV>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 什么是BlazeDS呢?BlazeDS是一个基于服务器的Java远程调用(remoting)和Web消息传递(messaging)技术,它能够使得后台的Java应用程序和运行在浏览器上的Flex应用程序相互通信。在各大搜索引擎里,关于BlazeDS的中文教程来来去去都是那几篇,而且都是使用Eclipse来开发Flex的(用Eclipse开发Flex跟Java很不错的)。这篇文章将会尝试着使用Flex Builder 3,用一个经典的“HelloWorld”例子来让你学会BlazeDS的使用方法。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在开始之前,你需要安装JDK和Tomcat并实现成功配置,详细请看:<A href="http://blog.chinaunix.net/u/21684/showart_195064.html" target=_blank><FONT color=#bb6f02>Tomcat 6.0 配置</FONT></A>。</P>
<P><STRONG>一、我电脑上的配置是如下四点,如果你电脑上的配置不同于以下四点,可能需要你对你的电脑进行修改一下:<BR></STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1、Window XP;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2、Tomcat 6.0,安装在“C:\Program Files\Apache Software Foundation\Tomcat 6.0\”,下文会使用“”来代替这长长的目录路径;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3、Tomcat服务器使用端口8080;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4、使用Flex Builder 3而非Eclipse。</P>
<P><STRONG>二、如果你对以下操作比较陌生,那你应该先熟悉一下以下操作:</STRONG><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1、写一个Java文件并编译它;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2、使用Flex Builder 3;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3、停止和开户Tomcat服务器。<SPAN id=more-69></SPAN></P>
<P><STRONG>三、下载BlazeDS:</STRONG><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1、网址:<A href="http://opensource.adobe.com/wiki/display/blazeds/Release+Builds" target=_blank><FONT color=#bb6f02>http://opensource.adobe.com/wiki/display/blazeds/Release+Builds</FONT></A> ;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2、下载那个“BlazeDS binary distribution”(<A href="http://download.macromedia.com/pub/opensource/blazeds/blazeds_bin_3-0-0-544.zip" target=_blank><FONT color=#bb6f02>http://download.macromedia.com/pub/opensource/blazeds/blazeds_bin_3-0-0-544.zip</FONT></A>);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i. 把那个 .zip 文件保存到你的电脑上<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ii. 里面有两个文件:blazeds.war 和 blazeds-bin-readme.html<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iii. 把里面的 blazeds.war 文件解压到这个目录下:\webapps<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3、如果Tomcat正在运行,请停止它然后再启动它(就是重启Tomcat);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4、打开这个目录:\webapps<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i. 你应该会看到一个名为“blaseds”的文件夹<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ii. 在blaseds文件夹里,会有一个名为“WEB-INF”的文件夹<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iii. 在WEB-INF文件夹里会有很多文件夹,其中有一个名为“classes”的文件夹。Flex应用程序需要使用到的Java class就是放到这个文件夹里的<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iv. 还有一个名为“flex”的文件夹,它里面有一个remoting-config.xml,我们要在这个remoting-config.xml文件里添加destination结点来告诉Flex应用程序如何连接上Java class的</P>
<P><STRONG><SPAN style="COLOR: #000000">四、使用文本编辑器编写以下这个Java文件并命名为“HelloWorld.java”:</SPAN></STRONG></P>
<DIV class=hl-surround>
<OL class="hl-main ln-show" .dblclick=linenumber(this) title="Double click to hide line number.">
<LI class=hl-firstline><SPAN style="COLOR: blue">package</SPAN><SPAN style="COLOR: gray"> </SPAN><SPAN style="COLOR: blue">cn</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: blue">riahome</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: blue">java</SPAN><SPAN style="COLOR: gray">;</SPAN>
<LI><SPAN style="COLOR: gray"></SPAN>
<LI><SPAN style="COLOR: green">public</SPAN><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: green">class</SPAN><SPAN style="COLOR: gray"> </SPAN><SPAN style="COLOR: blue">HelloWorld</SPAN><SPAN style="COLOR: gray"> </SPAN><SPAN style="COLOR: olive">{</SPAN>
<LI><SPAN style="COLOR: gray"></SPAN>
<LI><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: green">public</SPAN><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: blue">HelloWorld</SPAN><SPAN style="COLOR: olive">()</SPAN><SPAN style="COLOR: gray"> </SPAN><SPAN style="COLOR: olive">{</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: olive">}</SPAN>
<LI><SPAN style="COLOR: gray"></SPAN>
<LI><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: green">public</SPAN><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: teal">String</SPAN><SPAN style="COLOR: gray"> </SPAN><SPAN style="COLOR: blue">getHelloWorld</SPAN><SPAN style="COLOR: olive">()</SPAN><SPAN style="COLOR: gray"> </SPAN><SPAN style="COLOR: olive">{</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: green">return</SPAN><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: red">Hello World!</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: gray">;</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: olive">}</SPAN>
<LI><SPAN style="COLOR: olive">}</SPAN></LI></OL></DIV>
<P>编译这个Java文件并得到HelloWorld.class文件。在 \webapps\blazeds\WEB-INF\classes 目录下新建一个名为“cn”的文件夹,然后在cn文件夹新建一个“riahome”文件夹,接着在riahome文件夹里新建一个“java”文件夹,最后把刚才编译得到的HelloWorld.class文件放到java文件里,HelloWorld.class的路径应该为:\webapps\blazeds\WEB-INF\classes\cn\riahome\java\HelloWorld.class</P>
<P>五、打开 \ webapps\blazeds\WEB-INF\flex\remoting-config.xml 这个文件,然后在&lt;/default-channels&gt;标签之后和&lt;/service&gt;标签之前添加以下结点(注意id属性和source结点的值,source结点描述了完整的包路径和类名):</P>
<DIV class=hl-surround>
<OL class="hl-main ln-show" .dblclick=linenumber(this) title="Double click to hide line number.">
<LI class=hl-firstline><SPAN style="COLOR: olive">&lt;</SPAN><SPAN style="COLOR: green">destination</SPAN><SPAN style="COLOR: gray"> </SPAN><SPAN style="COLOR: #00008b">id</SPAN><SPAN style="COLOR: gray">=</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: red">helloWorld</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: olive">&gt;</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; </SPAN><SPAN style="COLOR: olive">&lt;</SPAN><SPAN style="COLOR: green">properties</SPAN><SPAN style="COLOR: olive">&gt;</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: olive">&lt;</SPAN><SPAN style="COLOR: green">source</SPAN><SPAN style="COLOR: olive">&gt;</SPAN><SPAN style="COLOR: gray">cn.riahome.java.HelloWorld</SPAN><SPAN style="COLOR: olive">&lt;/</SPAN><SPAN style="COLOR: green">source</SPAN><SPAN style="COLOR: olive">&gt;</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; </SPAN><SPAN style="COLOR: olive">&lt;/</SPAN><SPAN style="COLOR: green">properties</SPAN><SPAN style="COLOR: olive">&gt;</SPAN>
<LI><SPAN style="COLOR: olive">&lt;/</SPAN><SPAN style="COLOR: green">destination</SPAN><SPAN style="COLOR: olive">&gt;</SPAN></LI></OL></DIV>
<P><SPAN style="COLOR: #000000"><STRONG>六、如果Tomcat正在运行,请停止它然后再启动它(就是重启Tomcat);</STRONG></SPAN></P>
<P><SPAN style="COLOR: #000000"><STRONG>七、请按以下步骤新建一个名为“HelloWorld”的Flex Project:</STRONG></SPAN></P>
<P>
<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0 height=552 width=466 classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000><PARAM NAME="_cx" VALUE="12330"><PARAM NAME="_cy" VALUE="14605"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="http://easyphpchina.com/yboycn/RIAHome/Flex.Flash.AIR.AS3/BlazeDS_step1.swf"><PARAM NAME="Src" VALUE="http://easyphpchina.com/yboycn/RIAHome/Flex.Flash.AIR.AS3/BlazeDS_step1.swf"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="-1"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="Allow.Access" VALUE=""><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE=""><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0"><PARAM NAME="AllowNetworking" VALUE="all"><PARAM NAME="AllowFullScreen" VALUE="false">
<embed type="application/x-shockwave-flash" width="466" height="552"
src="http://easyphpchina.com/yboycn/RIAHome/Flex.Flash.AIR.AS3/BlazeDS_step1.swf"></embed></OBJECT></P>
<P>
<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0 height=638 width=740 classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000><PARAM NAME="_cx" VALUE="19579"><PARAM NAME="_cy" VALUE="16880"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="http://easyphpchina.com/yboycn/RIAHome/Flex.Flash.AIR.AS3/BlazeDS_step2.swf"><PARAM NAME="Src" VALUE="http://easyphpchina.com/yboycn/RIAHome/Flex.Flash.AIR.AS3/BlazeDS_step2.swf"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="-1"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="Allow.Access" VALUE=""><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE=""><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0"><PARAM NAME="AllowNetworking" VALUE="all"><PARAM NAME="AllowFullScreen" VALUE="false">
<embed type="application/x-shockwave-flash" width="740" height="638"
src="http://easyphpchina.com/yboycn/RIAHome/Flex.Flash.AIR.AS3/BlazeDS_step2.swf"></embed></OBJECT></P>
<P><STRONG>八、在 HelloWorld.mxml 文件的&lt;mx:Application&gt;&lt;/mx:Application&gt;标签之间添加如下代码:</STRONG></P>
<DIV class=hl-surround>
<OL class="hl-main ln-show" .dblclick=linenumber(this) title="Double click to hide line number.">
<LI class=hl-firstline><SPAN style="COLOR: olive">&lt;</SPAN><SPAN style="COLOR: green">mx:Script</SPAN><SPAN style="COLOR: olive">&gt;</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: olive">&lt;</SPAN><SPAN style="COLOR: gray">![</SPAN><SPAN style="COLOR: #00008b">CDATA</SPAN><SPAN style="COLOR: gray">[</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: #00008b">import</SPAN><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: #00008b">mx</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">rpc</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">events</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">FaultEvent</SPAN><SPAN style="COLOR: gray">;</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: #00008b">import</SPAN><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: #00008b">mx</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">controls</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">Alert</SPAN><SPAN style="COLOR: gray">;</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: #00008b">import</SPAN><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: #00008b">mx</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">rpc</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">events</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">ResultEvent</SPAN><SPAN style="COLOR: gray">;</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: #00008b">private</SPAN><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: #00008b">function</SPAN><SPAN style="COLOR: gray"> </SPAN><SPAN style="COLOR: #00008b">resultHandler</SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: #00008b">event:ResultEvent</SPAN><SPAN style="COLOR: gray">)</SPAN><SPAN style="COLOR: #00008b">:void</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 显示收到的 </SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: red">Hello World!</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: gray"> 数据</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: #00008b">Alert</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">show</SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: #00008b">event</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">result</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">toString</SPAN><SPAN style="COLOR: gray">(), </SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: red">提示</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: gray">);</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: #00008b">private</SPAN><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: #00008b">function</SPAN><SPAN style="COLOR: gray"> </SPAN><SPAN style="COLOR: #00008b">faultHandler</SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: #00008b">event:FaultEvent</SPAN><SPAN style="COLOR: gray">)</SPAN><SPAN style="COLOR: #00008b">:void</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: #00008b">Alert</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">show</SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: #00008b">event</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">fault</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: #00008b">toString</SPAN><SPAN style="COLOR: gray">(), </SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: red">提示</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: gray">);</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; ]]</SPAN><SPAN style="COLOR: olive">&gt;</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; </SPAN><SPAN style="COLOR: olive">&lt;/</SPAN><SPAN style="COLOR: green">mx:Script</SPAN><SPAN style="COLOR: olive">&gt;</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; </SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; </SPAN><SPAN style="COLOR: olive">&lt;</SPAN><SPAN style="COLOR: green">mx:RemoteObject</SPAN><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: #00008b">id</SPAN><SPAN style="COLOR: gray">=</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: red">remoteObject</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: gray"> </SPAN><SPAN style="COLOR: #00008b">destination</SPAN><SPAN style="COLOR: gray">=</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: red">helloWorld</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: gray"> </SPAN><SPAN style="COLOR: #00008b">source</SPAN><SPAN style="COLOR: gray">=</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: red">cn.riahome.java.HelloWorld</SPAN><SPAN style="COLOR: #8b0000">"</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: #00008b">result</SPAN><SPAN style="COLOR: gray">=</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: red">resultHandler(event)</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: #00008b">fault</SPAN><SPAN style="COLOR: gray">=</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: red">faultHandler(event)</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: olive">/&gt;</SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; </SPAN>
<LI><SPAN style="COLOR: gray">&nbsp; &nbsp; </SPAN><SPAN style="COLOR: olive">&lt;</SPAN><SPAN style="COLOR: green">mx:Button</SPAN><SPAN style="COLOR: gray">&nbsp;</SPAN><SPAN style="COLOR: #00008b">label</SPAN><SPAN style="COLOR: gray">=</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: red">发送</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: gray"> </SPAN><SPAN style="COLOR: #00008b">click</SPAN><SPAN style="COLOR: gray">=</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: red">remoteObject.getHelloWorld()</SPAN><SPAN style="COLOR: #8b0000">"</SPAN><SPAN style="COLOR: olive">/&gt;</SPAN></LI></OL></DIV>
<P><STRONG>九、按F11测试,你看到一个叫“发送”的按钮,按一下它,会弹出“Hello World!”,这是后台发送过来的。至此,我得恭喜您!您成功了!</STRONG></P>
<P><STRONG>十、最后需要注意的是:&lt;mx:RemoteObject&gt;标签的destination属性值必须跟remoting-config.xml文件里destination标签的id值一致!</STRONG></P>
<P><SPAN style="COLOR: #000000"><STRONG>如果您还是测试不成功,请注意以下几点:</STRONG></SPAN><BR>1、核实HelloWorld.class文件已经在\webapps\blazeds\WEB-INF\classes\cn\riahome\java目录下;<BR>2、检查remote-config.xml文件里是否已经添加了上述的&lt;destination&gt;标签;<BR>3、有没有重启Tomcat服务器;<BR>4、检查&lt;mx:RemoteObject&gt;标签有没有这两个属性:destination=”helloWorld”、source=”cn.riahome.java.HelloWorld”<BR>5、打开Flex Project的属性面板,查看 Flex Compiler 里的Additional compiler arguments选项,是否已经有“-services”指令,如下图(通常在新建Project的时候就自动添加的)<BR>
<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0 height=535 width=1044 classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000><PARAM NAME="_cx" VALUE="27623"><PARAM NAME="_cy" VALUE="14155"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="http://easyphpchina.com/yboycn/RIAHome/Flex.Flash.AIR.AS3/BlazeDS_step3.swf"><PARAM NAME="Src" VALUE="http://easyphpchina.com/yboycn/RIAHome/Flex.Flash.AIR.AS3/BlazeDS_step3.swf"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="-1"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="Allow.Access" VALUE=""><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE=""><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0"><PARAM NAME="AllowNetworking" VALUE="all"><PARAM NAME="AllowFullScreen" VALUE="false">
<embed type="application/x-shockwave-flash" width="1044" height="535"
src="http://easyphpchina.com/yboycn/RIAHome/Flex.Flash.AIR.AS3/BlazeDS_step3.swf"></embed></OBJECT><BR><BR>
<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0 height=535 width=1044 classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000><PARAM NAME="_cx" VALUE="27623"><PARAM NAME="_cy" VALUE="14155"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="http://easyphpchina.com/yboycn/RIAHome/Flex.Flash.AIR.AS3/BlazeDS_step3.swf"><PARAM NAME="Src" VALUE="http://easyphpchina.com/yboycn/RIAHome/Flex.Flash.AIR.AS3/BlazeDS_step3.swf"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="-1"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="Allow.Access" VALUE=""><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE=""><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0"><PARAM NAME="AllowNetworking" VALUE="all"><PARAM NAME="AllowFullScreen" VALUE="false">
<embed type="application/x-shockwave-flash" width="1044" height="535"
src="http://easyphpchina.com/yboycn/RIAHome/Flex.Flash.AIR.AS3/BlazeDS_step3.swf"></embed></OBJECT><BR>6、打开Flex Project的属性面板,再次检查 Flex Server 里的 Root folder、Root URL、Conntext root,按一下 Validate Location 按钮测试是否成功<BR>7、检查所有代码有没有错误</P></DIV>
页: [1]
查看完整版本: 用一个HelloWorl例子手把手教会你使用BlazeDS