创建Flex工程的步骤是:
1.打开Flexbuilder,file-->新建-->Flexproject。
2.下一步:注意上面三项,rootfolder指向的是[Tomcat-home]\webapps\blazeds。设置完成后启动tomcat点击ValidateConfiguration按钮,设置正确的话会成功。
3.Flex文件的代码是:
viewplaincopytoclipboardprint?
<?xmlversionxmlversion="1.0"encoding="utf-8"?> <mx:Applicationxmlns:mxmx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"layout="absolute"><mx:Script>
<![CDATA[
importmx.rpc.events.FaultEvent; importmx.controls.Alert; importmx.rpc.events.ResultEvent; privatefunctionresultHandler(event:ResultEvent):void
{
//显示收到的"HelloWorld!"数据
Alert.show(event.result.toString(),"提示");
}
privatefunctionfaultHandler(event:FaultEvent):void
{
Alert.show(event.fault.toString(),"提示");
}
]]>
</mx:Script> <mx:RemoteObjectidmx:RemoteObjectid="remoteObject"destination="helloWorld"source="Tree.HelloWorld" result="resultHandler(event)"fault="faultHandler(event)"/> <mx:Buttonlabelmx:Buttonlabel="发送"click="remoteObject.getHelloWorld()"/> </mx:Application>
<?xmlversionxmlversion="1.0"encoding="utf-8"?> <mx:Applicationxmlns:mxmx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"layout="absolute"><mx:Script>
<![CDATA[
importmx.rpc.events.FaultEvent; importmx.controls.Alert; importmx.rpc.events.ResultEvent; privatefunctionresultHandler(event:ResultEvent):void
{
//显示收到的"HelloWorld!"数据
Alert.show(event.result.toString(),"提示");
}
privatefunctionfaultHandler(event:FaultEvent):void
{
Alert.show(event.fault.toString(),"提示");
}
]]>
</mx:Script> <mx:RemoteObjectidmx:RemoteObjectid="remoteObject"destination="helloWorld"source="Tree.HelloWorld" result="resultHandler(event)"fault="faultHandler(event)"/> <mx:Buttonlabelmx:Buttonlabel="发送"click="remoteObject.getHelloWorld()"/> </mx:Application>
<?xmlversionxmlversion="1.0"encoding="utf-8"?> <mx:Applicationxmlns:mxmx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"layout="absolute"><mx:Script>
<![CDATA[
importmx.rpc.events.FaultEvent; importmx.controls.Alert; importmx.rpc.events.ResultEvent; privatefunctionresultHandler(event:ResultEvent):void
{
//显示收到的"HelloWorld!"数据
Alert.show(event.result.toString(),"提示");
}
privatefunctionfaultHandler(event:FaultEvent):void
{
Alert.show(event.fault.toString(),"提示");
}
]]>
</mx:Script> <mx:RemoteObjectidmx:RemoteObjectid="remoteObject"destination="helloWorld"source="Tree.HelloWorld" result="resultHandler(event)"fault="faultHandler(event)"/> <mx:Buttonlabelmx:Buttonlabel="发送"click="remoteObject.getHelloWorld()"/> </mx:Application>
<?xmlversionxmlversion="1.0"encoding="utf-8"?> <mx:Applicationxmlns:mxmx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"layout="absolute"><mx:Script>
<![CDATA[
importmx.rpc.events.FaultEvent; importmx.controls.Alert; importmx.rpc.events.ResultEvent; privatefunctionresultHandler(event:ResultEvent):void
{
//显示收到的"HelloWorld!"数据
Alert.show(event.result.toString(),"提示");
}
privatefunctionfaultHandler(event:FaultEvent):void
{
Alert.show(event.fault.toString(),"提示");
}
]]>
</mx:Script> <mx:RemoteObjectidmx:RemoteObjectid="remoteObject"destination="helloWorld"source="Tree.HelloWorld" result="resultHandler(event)"fault="faultHandler(event)"/> <mx:Buttonlabelmx:Buttonlabel="发送"click="remoteObject.getHelloWorld()"/> </mx:Application>
4.还没有结束,要设置[Tomcat-home]\webapps\blazeds\web-inf\Flex\remoting-config.xml,吧下面的代码添加到xml根节点下:
viewplaincopytoclipboardprint?
<destinationiddestinationid="helloWorld"> <properties>
<source>Tree.HelloWorld</source>
</properties>
</destination> <destinationiddestinationid="helloWorld"> <properties>
<source>Tree.HelloWorld</source>
</properties>
</destination>
<destinationiddestinationid="helloWorld"> <properties>
<source>Tree.HelloWorld</source>
</properties>
</destination> <destinationiddestinationid="helloWorld"> <properties>
<source>Tree.HelloWorld</source>
</properties>
</destination>
注意这里的id就是mxml代码里面RemoteObject对象的destination属性。source指向的就是我们拷贝到web-inf/classes里面编译后的class文件。
完成,重启tomcat。在Flexbuilder里面点运行,看到Helloworld,成功!