Source file download:Start downloading 10.1k
This article introduces the communication method between ColdFusion and flash. This time, the Remoting component is not used, but directly uses the NetConnection object to connect to ColdFusion's built-in Remoting service. This service adopts the message mechanism (action message format) of the AMF structure.
Please review the methods and attribute events of the NetConnection object first. Create a new NetConnection()networkConnect, connect method is used to connect to anetworkIf it is the rtmp protocol, the connection will return true, otherwise it will return false, and true will always be 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", receive object, parameter list,...)
Now: Open flashmx to create a new document size 550*150. The background is light cyan. Add 3 static text labels, one dynamic text box, enter one text box, and open the shared library to enter a button:: As shown in the figure below: (add content to the above controls)
Set as follows: input box inputbox button button1 display box showbox
Add the following code to the first frame:
Code copy box
The following is a quoted snippet: //Include file #include "" is mainly used for debugging and has no other meaning, optional parameters //=true; When the server does not support utf-8, the following code is added. #include "" conn=new NetConnection(); //Connect the gateway, which can be found in the flashmx window service browser. ("http://localhost:8500/flashservices/gateway"); //Call service //Define an object that receives the value returned var obj={}; //Define the event of receiving object onResult When a result is received, this event is triggered; =function (result) { = Results; trace(result); } = function(info){ trace("A error occurred" + ); } function function1() { //Use named parameters to pass objects. It is particularly convenient when there are many parameters, so it is recommended to use it. var obj2={}; =; ("FLASHTEST.f2c",obj,obj2); } //Define button event = function() { function1(); } |
Server code writing:
Create a new site: flashtest Create a new file
The code is as follows: Save location/flashtest/
<!--- Return to the current time of the server --->
<cfset theTime = timeFormat(now(), "h:mm:ss tt") >
<!---- Specific variable name Can call back to the client's .onresult --->
<!--- Set the data content of the result, ## Get the real-name data variable passed by flash. Otherwise, use [1] to obtain the variable. From the beginning of the array in cf, the first parameter is params[1]
--->
<cfset = "Welcome" & ## & "Use the world's leading cf server system, the standard time of CF is now " & theTime>
The effect of execution is as follows: