ColdFusion MX Remote Service Instance Introductory tutorial _coldfusion

Source: Internet
Author: User
Tags ming save file
This tutorial is divided into two parts: 1 Create a CF component 2 create a Flash application. Create a new site before you start. Creating a CF Component: Here we create a component that defines two functions [chaxun1,chaxun2], functions that use EXAMPLEAPPS database sources, Returns a query result object in which the Flash movie file invokes the component method and receives the returned query results. The CHAXUN1 function requires three parameters, which are passed from the Flash movie. (parameter is Xing Ming Cheng)
The steps created are as follows: Use DWMX (Dreamweaver mx abbreviation, same below), file → New: New Document dialog box, general card, dynamic page, select ColdFusion component. [As pictured]

Open the Palette [window → component] Click + Create a new component as shown in the figure: the Name box specifies the. CFC filename. Do not specify a. cfc file extension when you enter a name. The Component directory box specifies the location where the component will be saved. Add two functions to the component: Access is set to be used as a WEB service if you choose Remote from the Access menu. Make sure that you specify the appropriate type of the value returned by the function in the return value type box. To add a parameter to define one or more parameters for a function, select parameters from the section list, select the function from the pop-up menu, click the Plus (+) button, and then enter the details for the new parameter on the right. [Add three arguments for this function, type is a string]
To add a body to a function: Windows/Bindings Click + SELECT list of recordsets (query) Add a recordset Recordset1 enter the following query code:

SELECT Tblemployees.employeeid, TBLEMPLOYEES.DEPTIDFK, Tblemployees.firstname, Tblemployees.lastname, Tbldepartments.departmentname
From Tblemployees, tbldepartments
WHERE TBLEMPLOYEES.DEPTIDFK = Tbldepartments.departmentid
<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

Increase Recordset2 in the same way

Switch the document to Code view, cut Recordset1[<cfquery >...</cfquery to query 1 <!---CHAXUN1 body---> Paste, in the same way Recordset2 To query 2. Then set <cfreturn > Query 1 set to <cfreturn recordset1>

Query 2 is set to <cfreturn recordset2>

File/save file. Turn off dwmx and start flashmx.

Two create Flash movies.

1 files → create a new flash movie. Create a new layer, named script, and layer one named UI.
Select the component Flash MX UI component to put several components into the document, set as shown:

Code Copy Box

The following is a reference fragment:
#include "netservices.as"
#include "netdebug.as"
#include "dataglue.as"
if (inited = null)
{
Code that executes only once
Inited = true;
Set Default gateway URL
Netservices.setdefaultgatewayurl ("Http://localhost:8500/flashservices/gateway");
Connect to Gateway
Gateway_conn = Netservices.creategatewayconnection ();
Returns a reference to a service
MyService = Gateway_conn.getservice ("Flashtest.chaxun", this);
}
function query ()
{Trace (engineering. GetSelectedItem (). label);
Trace (name. text);
Trace (last name. Text);
MYSERVICE.CHAXUN1 (name. text, last name. Text, Project. GetSelectedItem (). label);
}
function Chaxun1_result (Result) {
Dataglue.bindformatstrings (display box, result, "#LastName #, #FirstName #, #DepartmentName #", "#EmployeeIDFK #");
}
function Chaxun2_result (Result) {
Dataglue.bindformatstrings (engineering, result, "#DepartmentName #", "#DepartmentID");
}
Myservice.chaxun2 ();

The results of the

Run 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.