flex与java的交互

  • 格式:doc
  • 大小:185.00 KB
  • 文档页数:7

Java和flash的交互
学习flex不能只学其外观的,要知道这么美的外观就是用来交互的,毫无疑问的事。

我今天就按照视屏教程做了一个相信能大家带来一些方便。

学习前得准备:
1
Myeclipse
Tomcat
Blazeds包
2先打开myeclipse新建一个web项目:
图1
图2 工程名叫flex_s
在工程里面的webroot里面进行“一删一加”(删除index,jsp,添加Blazeds包)
导入Blazeds包
选择系统文件
新建一个类
public class simpleService { public String add(String name)
{
return"hello"+name;
}
}
在远程配置里面添加这些语句:
<destination id="Service">
<properties>
<source>
service.simlpeService
</source>
</properties>
</destination>
打开tomcat发布一下:
这个大家都会把不在啰嗦了,
下面就是在flash builder4.X进行了
新建一个flex项目,在设置上要看清了和以前的可能不太一样啊。

只有在验证后出现web根文件夹和url有效才算成功啊……
就直接点finish。

在源码区添加如下代码:
<s:layout>
<s:VerticalLayout verticalAlign="middle"
horizontalAlign="center" paddingLeft="20"/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
protected function
remote_resultHandler(event:ResultEvent):void
{
b.text=event.result.toString();
}
protected function
button1_clickHandler(event:MouseEvent):void
{
remote.add(a.text.toString());
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<s:RemoteObject id="remote" destination="Service"
result="remote_resultHandler(event)"/>
</fx:Declarations>
<s:HGroup width="400" height="30" gap="20" verticalAlign="middle" paddingLeft="20">
<s:TextInput id="a"/>
<s:Button label="提交" click="button1_clickHandler(event)"/>
<s:TextInput id="b"/>
</s:HGroup>
打开tomcat运行在第一个输入任意的字符点击提交后面的就会自动的进行输出教程信息Ps:稍微解释一下mxml语句中点击提交会相应其函数,然后调用远程服务;远程服务得到的结果又会通过reulst对应的函数传递给第二个textInput。

我比较懒,有啥不懂得或者需要一些上述的工具可以联系我。

我的邮箱ownWell@。