ColdFusion and FLASH Communication getting started

Source: Internet
Author: User

Preparations before use: You need to prepare the test environment flash mx ColdFusionMX
Download source file: Start to download 10.1 k
This article describes the communication between ColdFusion and flash. Instead of using the Remoting component, you can directly use the NetConnection object to connect to ColdFusion's built-in Remoting service. the Service uses the AMF message structure (Action Message format ).
Please first review the methods and attribute events of the NetConnection object. new NetConnection () creates a network connection. The connect method is used to connect to a network. If the rtmp protocol is used, true is returned for successful connection; otherwise, false is returned; and true is always returned for http connections. to determine whether the connection is successful, you can also use the onStatus event.
Close is used to close the connection. call is used to call a service, online object. call ("service", receiving object, parameter list ,...)
Now: Open flashmx to create a document with the size of 550*150. The background is light blue. add three static text labels, one dynamic text box, and one text box. Open the shared folder and enter a button, as shown in: (add content to the above control)

Set as follows: Enter the inputbox button button1 to display the box showbox

Add the following code to the first frame:

Code copy box

The following is a reference clip:
// Contains the file # include "NetDebug. as", which is mainly used for debugging and has no other meaning. Optional Parameter
// System. useCodePage = true; Add the following code when the server does not support UTF-8.
# Include "NetDebug."
Conn = new NetConnection ();
// Connect to the gateway, which can be found in the flashmx window service browser.
Conn. connect ("http: // localhost: 8500/flashservices/gateway ");
// Call service
// Define an object that receives the returned value
Var obj = {};
// Define the onResult of the received object event. This event is triggered when a result is received;
Obj. onResult = function (result ){
Showbox. text = result;
Trace (result );
}
Obj. onStatus = function (info ){
Trace ("an error occurred" + info. code );
}
Function function1 (){
// Use named parameters to pass objects. It is especially convenient when there are many parameters. We recommend that you use them.
Var obj2 = {};
Obj2.sj = inputbox. text;
Conn. call ("FLASHTEST. f2c", obj, obj2 );
}
// Define button events
Button1.onPress = function (){
Function1 ();
}

Write server code:
New Site: flashtest new file f2c. cfm
The Code is as follows: Save location/flashtest/f2c. cfm
<! --- Return the current server time --->
<Cfset theTime = timeFormat (now (), "h: mm: ss tt")>
<! --- The specific variable name Flash. result can be called back to the client's. onresult --->
<! --- Set the data content of the result, # Flash. sj # obtain the real-name data variable passed by flash. otherwise, use flash. get the variable from params [1]. The array in cf starts from the beginning. The first parameter is params [1].
--->
<Cfset flash. result = "welcome" & # Flash. sj # & "using the world's leading cf server system, now the standard CF time is" & theTime>

The execution result is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.