首頁 > ColdFusion, FLEX > FLEX AS3與ColdFusion進行Remoting = 傳值篇

FLEX AS3與ColdFusion進行Remoting = 傳值篇

2009年2月11日  瀏覽次數 : 2,486

在前篇中 使用 FLEX AS3 與 ColdFusion 建立 Remoting 提到如何設定 ColdFusion 以及 FLEX 專案以完成 Remoting 從 SERVER 端取回資料,那該怎麼把資料送到 SERVER 端呢 ? 別急… 這篇告訴你 !

image

首先我們修改上次的 helloworld.cfc 檔案,並且放在與上次相同的路徑 comp 底下

helloworld.cfc

?View Code COLDFUSION
1
2
3
4
5
6
7
<cfcomponent>
	<cffunction name="sayHellow" returntype="String" access="remote">
    	<cfargument name="firstname" required="yes" type="string">
        <cfargument name="lastname" required="yes" type="string">
		<cfreturn "#firstname# #lastname# 您好 ! 這是你的 sayHellow 方法">
	</cffunction>
</cfcomponent>

接下來我們來修改 remotingTest.mxml 來負責將兩個欄位上傳至 SERVER 端,並且組合字串顯示在客戶端的 FLEX 畫面上。

remotingTest.mxml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" fontSize="16">
	<mx:Script>
		<![CDATA[
			//執行 sayHellow 方法
			private function clickHandler():void
			{
				var obj:Object=new Object();
				obj.firstname=this.firstname.text;
				obj.lastname=this.lastname.text;
				this.roTest.sayHellow(obj);
			//或是你也可以分別丟入參數資料
			//this.roTest.sayHellow(this.firstname.text,this.lastname.text);
			}
		]]>
	</mx:Script>
	<mx:RemoteObject id="roTest" destination="ColdFusion" source="comp.helloworld" result="this.testLabel.text = this.roTest.sayHellow.lastResult"/>
	<mx:Label id="testLabel" text="尚未取得SERVER資料"/>
	<mx:Form width="246">
		<mx:FormItem label="姓 : ">
			<mx:TextInput id="firstname"/>
		</mx:FormItem>
		<mx:FormItem label="名 : ">
			<mx:TextInput id="lastname"/>
		</mx:FormItem>
		<mx:FormItem>
			<mx:Button label="送出" click="clickHandler()"/>
		</mx:FormItem>
	</mx:Form>
</mx:Application>

image

接下來我們執行 FLEX 程式後,輸入姓名並寫送出,我們便可得到「方 大同 您好 ! 這是你的 sayHellow 方法 」。

Random Posts

Loading…

:: 把這篇好文推到書籤網站與更多人分享吧 ::
  • funp
  • Hemidemi
  • YahooKimo
  • Google
  • udn
  • Haohao
  • Live

相關文章 :

Ausir ColdFusion, FLEX , , , ,