ColdFusion and Flash communication easy to start tutorials _coldfusion

Source: Internet
Author: User
Tags current time
Pre-use preparation: You need to prepare the test environment Flash MX COLDFUSIONMX
Source file Download: Start downloading 10.1k
This article describes ColdFusion and flash communication, this time without the use of remoting components, directly using the Netconnection object, connect to the ColdFusion of the built-in remoting service. The service uses the message mechanism of the AMF structure ( Action message format).
Please brush up on the Netconnection object's method and property events. New Netconnection () new network connection, connect method for connecting to a network if the connection is rtmp, return true if it succeeds, or false. The connection to HTTP always returns TRUE. To determine whether a connection is successful, you can also use the Onstatus event.
Close is used to turn off the connection. Call is used to invoke a service, online object. Calls ("Services", receiving objects, parameter lists,...)
Now: Open flashmx New Document size 550*150 background is light cyan. Add to static text label 3, dynamic text box One, input text box one, open shared library push a button:: (Add content for above control)



The settings are as follows: the Input Box InputBox button button1 Display box Showbox

Add the following code to the first frame:


Code Copy Box

The following is a reference fragment:
Include file #include "netdebug.as" is primarily used for debugging and has no other meaning, optional parameters
System.usecodepage=true when the server does not support Utf-8, add the following code.
#include "netdebug.as"
Conn=new netconnection ();
Connect the gateway, which can be found in the FLASHMX window service browser.
Conn.connect ("Http://localhost:8500/flashservices/gateway");
Call service
Defines an object that receives the returned value
var obj={};
Defines the Receive object event Onresult When a result is received, this event is triggered;
Obj.onresult=function (Result) {
Showbox.text = result;
Trace (result);
}
Obj.onstatus = function (info) {
Trace ("An error occurs" + Info.code);
}
function Function1 () {
Using named parameters to pass the object, when the argument is more, especially convenient, recommended.
var obj2={};
Obj2.sj=inputbox.text;
Conn.call ("flashtest.f2c", obj,obj2);
}
Defining button Events
button1.onpress = function () {
Function1 ();
}

Server code writing:
New site: flashtest new File f2c.cfm
The code is saved in the following location/flashtest/f2c.cfm
<!---returns the current time of the server--->
<cfset thetime = TimeFormat (now (), "H:mm:ss tt") >
<!---a specific variable name Flash.result can be invoked to the client. Onresult--->
<!---set the data content of result, #Flash. sj# obtains the real name data variable which the Flash passes over. Otherwise use flash.params[1] to get the variable, the array in CF from the beginning, the first argument is params[1]
--->
<cfset Flash.result = "Welcome" & #Flash. Sj# & "Using the world's leading CF server system, now CF's Standard Time is" & thetime>

The results of the execution are 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.