Flash Buider与myEclipse联合开发

ActionScript是Adobe公司为开发Flex应用提供的脚本语言,它与javaScript有许多相似之处,前端轻量级脚本语言,更偏向于关注前端用户交互。他与服务端交互要借助于一些组件,如livecycle Data Service和BlazeDS。

blazeDS是开源免费的,LCDS是付费和闭源的。在这里我们使用blazeDS。

1、下载blazeds-turnkey并解压。

2、在myEclipse中创建web project,把blazeds-turnkey\tomcat\webapps\blazeds下的WEB-INF复制到所创建的web project的Webroot目录下,选择覆盖。

3、创建class,名为FlexServer

package com.lijia;

public class FlexServer {
	public String sayHello(String msg){
		System.out.println("Hello Flex");
		return "Hello " + msg;
	}
}

4、修改WEB-INF\flex\remoting-config.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service" 
    class="flex.messaging.services.RemotingService">

    <adapters>
        <adapter-deFinition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
    </adapters>

    <default-channels>
        <channel ref="my-amf"/>
    </default-channels>
    <!-- 以下添加 -->
    <destination id="serverTag">
    	<properties>
    		<source>com.lijia.FlexServer</source>
    	</properties>
    </destination>

</service>

5、部署项目到tomcat,并启动服务

6、在flash Buider中新建Flex项目,应用程序类型选web




注意:根文件夹是myEclipse所创建的web project部署到tomcat下的目录

7、打开mxml文件,编辑

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
		<mx:RemoteObject id="clientTag" destination="serverTag" result="callMe(event)" endpoint="/flexServer/messagebroker/amf">
			
		</mx:RemoteObject>
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.rpc.events.ResultEvent;
			private function showAlert():void{
				var str:String = new String("who are you? ");
				Alert.show(str,"show");
				clientTag.sayHello(str);
			}
			private function callMe(event:ResultEvent):void{
				Alert.show(event.result.toString());
			}
		]]>
	</fx:Script>
	<s:Panel width="459" height="322">
		<s:Button x="173" y="98" label="按钮" click="showAlert()"/>
	</s:Panel>
</s:Application>

8、大功告成,点击按钮,将调用java文件


相关文章

  译序:JWMediaPlayer是开源的网页使用的Flash播放器。本...
    Flash编程原理都是只能将1写为0,而不能将0写成1.所...
 上传setenvgatewayip192.168.1.1;setenvserverip192.168.1...
Error:FlashDownloadFailed-"Cortex-M3"出现一般有...
jPlayer是一个用于控制和播放mp3文件的jQuery插件。它在后台...
#ifndef__FONTUPD_H__#define__FONTUPD_H__#include"sy...