月光石

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: :: :: 管理 ::

[声明:版权归原创所有http://hi.baidu.com/duqian1985/blog/item/bb3bdf062fe95a73020881dd.html]

step 1.下载 flex 3.0 plugin 插件 装在 我的myeclipse 6.0 上

   1) 下载地址:http://trials.adobe.com/Applications/Flex/FlexBuilder/3/FB3_WWEJ_Plugin.exe

   2)安装插件

    将flex plugin 安装目录里面的com.adobe.flexbuilder.update.site 文件夹下面的features 文件夹,plugins 文件夹 和 site.xml 文件 添加在myeclipse 文件夹的eclipse文件夹内.

              将 flex plugin 安装目录里面的eclipse 文件夹下面的features 文件夹,plugins 文件夹 覆盖在myeclipse 文件夹的eclipse文件夹内.(防止更新)

step1 完

 

step 2.下载 blazeds  

http://download.macromedia.com/pub/opensource/blazeds/blazeds_bin_3-0-0-544.zip

解压之后是个 blazeds. war包,把它放在tomcat 的webapp里面 部署一下就会释放出来一个类似与工程文件的东西(里面就有将flex 和java 合并的重要文件)

step 2 完

step 3 . 合并 web project 和flex 工程

新建一个web project 工程

把 blazeds.war 部署之后的 flexweb 文件夹里面的lib 目录copy 到 web-inf 的lib目录里

把 blazeds.war 部署之后的 flexweb 文件夹里面的flex 目录copy 到 web-inf 下面

替换 web.xml 这步很重要,容易忘记,忘记你就死定了,慢慢调去吧!

都加完了把? 这时候把web project 工程部署在tomcat上面上他跑起来, 之后在加入flex ,单击工程右键flex project natrue --- > add flex project natrue

第一步见下图


 

第二步见下图


 

都整完了看一下配置是否正确,正确就可以进行 step 4了。

step 3 完


step 4 . 让flex调用java类(这tm才是我们想要到达的目的!)

在src 里面见一个包,包里面见一个类 包名.类名 whatever

开始配置 remoting-config.xml

在里面加入

    <destination id="hello">
         <properties>
             <source>com.Hello</source>
        </properties>
    </destination>

hello 是别名

com.hello 是类的全路径

然后配置services-config.xml(这个tm那个介绍配置上面也没写,你说你到是告诉一声啊,向我们这种粗心大意的人那在乎啊,就因为这个没配置我就浪费了2个小时,我只能对那些网上发帖子教人家配置的大牛们,说一声:"大哥在说的详细点被")

        <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://127.0.0.1/flexweb/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint" />
    
        </channel-definition>

        <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
            <endpoint url="https://127.0.0.1/flexweb/messagebroker/amfsecure " class="flex.messaging.endpoints.SecureAMFEndpoint"/>
            <properties>
                <add-no-cache-headers>false</add-no-cache-headers>
            </properties>
        </channel-definition>

        <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://127.0.0.1/flexweb/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
            <properties>
                <polling-enabled>true</polling-enabled>
                <polling-interval-seconds>4</polling-interval-seconds>
            </properties>
        </channel-definition>

主要就是把那个 url 改成自己的工程 路径,太tm 重要了!

step 4 完


使用 :

写一个hello类

public class Hello {
    public String hello(String name){
        System.out.println(name);
        return "hello"+name;
    }
}

一个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.ResultEvent;
function gg(evnet:ResultEvent):void{
var ff:String = evnet.result as String;
ggg.text = ff;
}
function remotingSayHello():void{
var sname:String = nameInput.text;
h.hello(sname);
}
]]>
</mx:Script>
<mx:RemoteObject destination="hello" id="h"
result="gg(event)" endpoint="http://127.0.0.1/flexweb/messagebroker/amf" >
</mx:RemoteObject>
<mx:TextArea id="ggg" x="109" y="122"/>
<mx:Button label="say hello" click="remotingSayHello();" x="144" y="193"/>
<mx:TextInput id="nameInput" x="109" y="73"/>
<mx:Label text="name" x="47" y="75"/>
</mx:Application>


posted on 2009-09-24 23:46  月光石  阅读(3642)  评论(0编辑  收藏  举报