FlashDevelop是我很喜欢的一款的AS开发IDE,以至于现在本人在重装了系统之后都木有再安装Flex Builder。
在Flex Builder下配置Remoting Google一下都有比较详细的图文教程,不过FlashDevelop下我还没找到。虽然说差别不大,但是呢,有几个注意点还是比较容易引起错误的。
现在假设服务器端已经配置完毕,我使用的服务端是基于.net 的fluorine。服务器处理段地址是:http://localhost/Gateway.aspx
服务端现在有一个远程处理类Dada。两个方法
- helloWorld 返回的是一个String:"FxRemoting return HelloWorld"
- GetSum(int numA,int numB):求和,返回的是一个int类型的和。
好,现在开始客户端的配置。先准备好代码:
ActionScript Code
import mx.rpc.remoting.*;
import mx.rpc.events.*;
import mx.controls.Alert;
private function test():void
{
var remoteObj:RemoteObject = new RemoteObject();
remoteObj.destination = "fluorine"
//destination 根据services-config.xml(fluorine自动生成的放在remoting-config.xml中)中的<destination id="fluorine">中的id决定,当然,你也可以取其他名字。
remoteObj.source = "Dada";
remoteObj.GetSum.addEventListener("result", getListResultHandler);
remoteObj.addEventListener("fault", faultHandler);
remoteObj.GetSum(3,6);
}
public function getListResultHandler(event:ResultEvent):void {
// Do something
Alert.show(event.result);
}
public function faultHandler (event:FaultEvent):void {
// Deal with event.fault.faultString, etc.
Alert.show(event.fault.faultString, 'Error');
}
这是使用RemotingObject的测试GetSum的代码。
现在还要添加编译参数。Follow me:
选择Additional Compiled Options右边的小按钮,弹出:
输入如下内容
-services ..\FluorineFxTest\WEB-INF\flex\services-config.xml
-context-root /
这里要着重声明一下: –services 后面跟着的是远程配置端的配置文件,里面的内容一般不需要修改。路径可以使用绝对路径也可以使用相对路径,相对的是FlashDevelop根目录。再特别特别注意一下,-services 后面不需要的路径千万不要跟引号。不然会报以下错误:
command line: Error: unable to open ‘"..\FluorineFxTest\WEB-INF\flex\services-config.xml"’
Use ‘mxmlc -help’ for information about using the command line.
Build halted with errors (fcsh).
-context-root 指的是Gateway.aspx所在的目录,比如http://www.isdada.com/fluo/Gateway.aspx,则为-context-root /fluo
好了,现在应该可以测试成功了。
当然,您可能会出现各种各样的问题,请参照:
HOHO,达达,这是为什么呢?
还是用Flex吧!
我用的就是Flex呀。你指的是否是Flex Builder?我是忍受够了那庞大的身躯,编译速度是如此缓慢……