迈向flex 的第二步 ----FLEX 与 VS 2008 利用 FluorineFx 开发快
?本文主要介绍flex和vs结合,并使用fluorineFx 进行企业级开发的配置演示。写该文章一方面是加深记忆以后方便自己查找,另一方面方便大家互相交流。
准备工作? FLEX 4.0 + VS 2008 + FluorineFx 1 、安装FluorineFx,具体不再介绍,下载之后一直下一步就OK VS2008 配置部分 1)、新建解决方案,并添加FluorineFx ServiceLibrary 项目,如下图所示 2)、上步操作完成之后,再添加新建网站,如下图所示: 以上操作完成之后,将如下图所示结构,如图: 在菜单栏中 找到 【生成 】选项,选择【生成解决方案】子项 如图所示,设置Console.aspx为起始页面,并运行解决方案。如下图所示, 如图所示,出现这样的界面表示.NET服务端项目已经搭建并运行成功,并可以输入一些内容进行测试连接。
FLEX 配置部分 1)、新建Flex项目,并且拷贝三个文件到Flex项目的src目录,如下图: 如图所示,之所以这样拷贝是为了避免如大家经常看到的其他文章中写的一些繁琐的配置,本文就是为了避免这样繁杂的配置,将配置文件单独分离,更好的理解, 客户端和服务器端分离开发,在接下来的介绍中将进一步介绍,如何配置。 2)、配置flex相关xml文件。 打开flex中的services-config.xml文件,找到如下部分: <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"> <endpoint uri="http://{server.name}:{server.port}/{context.root}/Gateway.aspx" class="flex.messaging.endpoints.AMFEndpoint"/> <properties> <!-- <legacy-collection>true</legacy-collection> --> </properties> </channel-definition>
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"> <endpoint uri="http://localhost:2650/Web/Gateway.aspx" class="flex.messaging.endpoints.AMFEndpoint"/> <properties> <!-- <legacy-collection>true</legacy-collection> --> </properties> </channel-definition>
接下来还要进行一项配置,点击flex项目右键属性,并选择第二项,如下图所示,并添加相应代码, 该操作目的是为flex指定一些服务参数,应该可以意会出这个意思。 好,到这里配置就完成了,接下来将进行项目测试阶段。 项目测试 直接贴出flex部分代码,如下: <?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" backgroundColor="#DCDCDC"> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> <s:RemoteObject id="Service" destination="fluorine" source="ServiceLibrary.Sample"> <s:method name="Echo" result="onResult(event)"> </s:method> </s:RemoteObject> <!-- 这里需要注意的是destination需要设置为与remoting-config.xml中的destination的id一致,source则配置为远程对象的全路径(名称空间+类),通过<mx:method>标签配置远程对象下的方法并设置其成功调用后的结果处理函数,下面便可通过id去调用远程方法了。--> </fx:Declarations> <fx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; private function onResult(evt:ResultEvent):void { this.edResult.text=evt.result.toString(); } protected function btnSend_clickHandler(event:MouseEvent):void { Service.Echo(edInput.text); } ]]> </fx:Script> <s:Panel x="61" y="28" width="336" height="201" title="Remoting Practice"> <s:Label x="39" y="51" text="输入: "/> <s:TextInput id="edInput" x="82" y="45"/> <s:Button id="btnSend" x="218" y="46" label="获取" width="51" click="btnSend_clickHandler(event)"/> <s:Label x="39" y="77" text="结果:"/> <s:TextInput id="edResult" x="83" y="75" width="186"/> </s:Panel> </s:Application>
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |