This tutorial consists of two parts: 1. Create CF component 2. Create a flash application. create a site before you start. 1. Create a CF component: here we create a component to define two functions: [chaxun1, chaxun2]. The function uses the exampleapps database source to return a query result object, call the component method of the flash Movie File and receive the returned query results. the chaxun1 function requires three parameters, which are passed from the flash Movie. (The parameter is xing ming cheng)
The steps are as follows: Use dwmx (short for Dreamweaver MX, the same below), file → New: New Document dialog box, regular card, dynamic page, select ColdFusion component. []
Open the component Panel [Window → component] and click + create a component: "name" box to specify the. cfc file name. Do not specify the. cfc file extension when entering the name. The "component directory" box specifies the location where the component will be saved. Add two functions for the component: the access method is set to "remote" from the "access" menu, the function can be used as a Web service. Make sure that the appropriate type of values returned by the function is specified in the "Return Value Type" box. Add one or more parameters to define a function. Select "parameter" from the "part" list, select the function from the pop-up menu, and click the plus sign (+, enter the details of the new parameter on the right. [Add three parameters for this function, all of which are strings]
Add a subject for the function: Add Recordset1 in the window/Bind click + select record set (query) in the list and enter the following query code:
SELECT tblEmployees. EmployeeID, tblEmployees. DeptIDFK, tblEmployees. FirstName, tblEmployees. LastName, tblDepartments. DepartmentName
FROM tblEmployees, tblDepartments
WHERE tblEmployees. DeptIDFK = tblDepartments. Dimension mentid
<Cfif isDefined ("ming")>
And tblEmployees. firstName like '# ming # %'
</Cfif>
<Cfif isDefined ("xing")>
And tblEmployees. lastName like '# xing # %'
</Cfif>
<Cfif isDefined ("cheng")>
And tblDepartments. DepartmentName like '# cheng # %'
</Cfif>
Order by tblEmployees. LastName, tblEmployees. FirstName
Add Recordset2 in the same way
Switch the document to the Code view and cut Recordset1 [<cfquery>... </cfquery>] to query 1 <! --- Chaxun1 body ---> paste it, Recordset2 in the same way to query 2. Then set <cfreturn> query 1 to <cfreturn Recordset1>
Set query 2 to <cfreturn Recordset2>
File/save the file. Disable dwmx and start flashmx.
2. Create a flash video.
1 file → create a new flash video. Create a new layer named script and Layer 1 named ui.
Select the Flash mx ui component and place several components in the document. Set:
Code copy box
The following is a reference clip: # Include "NetServices." # Include "NetDebug." # Include "DataGlue." If (inited = null) { // Code executed only once Inited = true; // Set the default gateway url NetServices. setdefagategatewayurl ("http: // localhost: 8500/flashservices/gateway "); // Connect to the Gateway Gateway_conn = NetServices. createGatewayConnection (); // Return a service reference MyService = gateway_conn.getService ("FLASHTEST. chaxun", this ); } Function query () {Trace (project. getSelectedItem (). label ); Trace (name. text ); Trace (last name. text ); MyService. chaxun1 (name. text, last name. text, project. getSelectedItem (). label ); } Function chaxun1_Result (result ){ Define Lue. bindFormatStrings (display box, result, "# LastName #, # FirstName #, # DepartmentName #", "# EmployeeIDFK #"); } Function chaxun2_Result (result ){ Define Lue. bindFormatStrings (Project, result, "# DepartmentName #", "# define mentid "); } MyService. chaxun2 (); |
The running result is as follows: