梦幻之旅

DEBUG - 天道酬勤

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  671 随笔 :: 6 文章 :: 256 评论 :: 0 Trackbacks

我们要实现的目的:

    1.希望在myeclipse里面可以创建flex项目。

    2.在flex中编辑的mxml文件,保存后能够自动的生成flash文件和html文件以供测试,当然正式发布的时候很多的HTML是要删除的。

    3.利用myeclipse在工程中实时同步机制,把我们编译后的flash和html文件直接同步到web工程,然后工程自动部署到tomcat,这样测试就很方便了,因为同步flash和html文件到tomcat根本就不用重新启动。

    注意我们的关键点本质上只是把flex项目的编译输出直接到web工程。

    好了,现在开始准备工具:

    环境搭建: Java5.0,tomcat5.5,eclipse 3.2(及以上),myeclipse(5.5及以上),FB3_WWEJ_Plugin.exe等等,按顺序都把他们先装上,然后myeclipse里面配置好tomcat这个就不详细说了。然后去下载个blazeds,这个自己去搜索吧!(我的附件里面有)

    blazeds与web工程的搭建: myeclipse中先创建个web项目myflex,注意要导入blazeds里面的相关jar,web.xml,还有WEB-INF里面flex目录下面的所有文件。最好的操作方法是,先把blazeds解压,然后再新建的工程里面WebRoot -> 右键 -> import -> File System -> next -> 选择你解压后的blazeds 目录, finish。这样会有提示是否要覆盖,点yes to all就OK了。

接下来在服务器端可以简单的写个helloWorld的类了,相关的配置弄好

package com.spell;

public class HelloWorld {

    public String sayHello(String name) {

        return "hello," + name;

    }

}

WebRoot/WEB-INFO/remoting-config.xml 中加入 id="Hello" destination

    <destination id="Hello">

       <properties>

           <source>com.spell.HelloWorld</source>

       </properties>

    </destination>

ok,可以部署到tomcat了,并且启动tomcat,这个时候不要着急着去测试

    flex工程的搭建: 这个是最让人恼火的地方了,这个地方上我走了很多的弯路,看那了网络上很多人所谓的配置,结果差点把我给搞死。后来还是自己的思路清晰点。

    建个flex工程,输入工程的名称flexTest,application type 选择 web application, server technology 选择none,点next,output folder 中选择你上面建立web工程的目录(MyEclipse里就是myflex工程目录下的WebRoot了), 这个很重要了,要不这边flex就不会自动到web工程了,那只有人工的拷贝了,这样做是很悲哀滴!!最后finish,好了这样flex工程也好了

 

flexTest.mxml文件
------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml " layout="absolute">
<mx:Script >     
<![CDATA[ import mx.rpc.events.FaultEvent;   
   import mx.rpc.events.ResultEvent;   
      [Bindable]   
      private var helloResult:String;   
      
      private function sayHello():void {   
        ro.sayHello(inputText.text);   
        }    
        
       private function resultHandler(event:ResultEvent):void {   
          helloResult = event.result as String;   
       }
       
   ]]>  
</mx:Script >
<mx:RemoteObject id="ro" destination="Hello" result="resultHandler(event)"
endpoint="/myflex/messagebroker/amf" />
<mx:HBox x="0" y="10" width="100%">
   <mx:Label text="Name:" id="nameLabel"/>
   <mx:TextInput id="inputText"/>
   <mx:Button label="say Hello" id="nameButton" click="sayHello()"/>
   <mx:Label id="resultLabel" text="{helloResult}"/>
</mx:HBox>
</mx:Application>

    这个文件好了后,你只要保存下就可以敲入URL测试了(保存后马上就output到myflex项目中了,然后又自动同步到tomcat,前面tomcat已经启动了),我的是http://localhost:8080/myflex/flexTest.html ,表单中输入名字,然后点下按钮,就跟你说hello了,是不是很兴奋了,恭喜flex你入门了。这里一定要指定endpoint, 要不然与服务器的交互会失败,endpoint的/myflex根据你web项目的名称不同而不同。endpoint不要指定死,如:http://localhost:8080/myflex/messagebroker/amf ,这样到了以后部署的时候是会有错误的。


转自:http://holdbelief.javaeye.com/blog/227394

posted on 2010-10-25 11:09 HUIKK 阅读(772) 评论(0)  编辑  收藏 所属分类: FLASH

只有注册用户登录后才能发表评论。


网站导航: