108
Chapter 6: Using Flash Remoting with ColdFusion MX
The following example replicates the
helloWorld()
function that was previously implemented as
a ColdFusion page. For more information, see
“Using Flash Remoting with ColdFusion pages”
on page 97
.
To create a ColdFusion component that interacts with a Flash application:
1.
Create a ColdFusion component, and save it as flashComponent.cfc in the helloExamples
directory.
2.
Edit flashComponent.cfc so that it appears as follows:
<cfcomponent>
<cffunction name="
helloWorld
" access="remote" returnType="Struct">
<cfset tempStruct = StructNew()>
<cfset tempStruct.timeVar = DateFormat(Now ())>
<cfset tempStruct.helloMessage = "Hello World">
<
cfreturn tempStruct
>
</cffunction>
</cfcomponent>
This example creates the
helloWorld
function. The
cfreturn
tag returns the result to the
Flash application.
3.
Save the file.
The following ActionScript example calls this function:
import mx.remoting.Service;
import mx.remoting.PendingCall;
//…
var CFCService:Service = new Service(
"http://localhost/flashservices/gateway",
null,
"helloExamples.flashComponent",
null,
null);
var pc:PendingCall = CFCService.helloWorld();
For ColdFusion components, the component filename, including the directory structure from the
web root, serves as the service name. Remember to use a period to delimit the path directories,
rather than a backslash.
Accessing ActionScript objects
ActionScript supports the object initializer syntax when calling a function. For example, the
following function call passes two parameters as objects:
myService.myMethod({x:1, y:2});
In this example, the function passes
x
with a value of 1 and
y
with a value of 2.
In your component, you can access objects using the object name, as in the following example:
<cfcomponent>
<cffunction ...>
<cfargument name="x" type="numeric">
<cfargument name="y" type="numeric">
Содержание FLASH REMOTING MX-USING FLASH REMOTING FOR FLASH MX 2004 ACTIONSCRIPT...
Страница 1: ...Using Flash Remoting for Flash MX 2004 ActionScript 2 0...
Страница 8: ...8 Contents...
Страница 62: ...62 Chapter 3 Using the RemotingConnector component Flash Professional only...
Страница 142: ...142 Chapter 7 Using Flash Remoting for Java...