ColdFusion to ActionScript data conversion issues
69
The following is additional information on conversion from server data types to ActionScript
data types:
•
If a string data type on the server represents a valid number in ActionScript, Flash can
automatically cast it to a number if needed.
•
If you use the
setType()
method to assign an object type to a flashgateway.io.ASObject object
on the server, and the type name matches the name of a registered class in ActionScript, Flash
Remoting creates an instance of that type in ActionScript. For more information see
“Working
with ActionScript typed objects” on page 71
.
•
To return multiple, independent, values to your Flash application, place them in a complex
server variable that can hold all the required data, such as a variable that converts to a Flash
Object, Array, or Associative Array data type. Return the single variable and use its elements in
the Flash application.
ColdFusion to ActionScript data conversion issues
ColdFusion is a
loosely typed
(
untyped
) language, where the data type of a variable can be
ambiguous. As a result, Flash Remoting cannot always determine how to convert between
ColdFusion data and ActionScript data. Boolean data in ColdFusion
If a ColdFusion page or CFC returns Boolean values, it represents these values as strings. Flash
does not have rules for converting strings to Boolean values. Instead, it converts the string to a
number, and then converts the number to a Boolean value. This operation converts all
representations of Boolean values except 1, which equates to the Boolean value of
true
, to
false
.
Therefore Flash converts ColdFusion Boolean values of
"Yes"
,
"True"
, and
true
to
false
.
To return a Boolean value correctly from ColdFusion to ActionScript, do either of the following:
•
Return a 1 (
true
) or 0 (
false
) numeric or string value. For example, the following function
converts any ColdFusion Boolean value to a value that ActionScript can use correctly. (For
simplicity, this example omits error-handling code.) Your ColdFusion page can call this
function before returning a Boolean value to Flash Remoting:
<cffunction name="convertBool">
<cfif Arguments[1] >
<cfreturn "1">
<cfelse>
<cfreturn "0">
</cfif>
</cffunction>
•
Specify the
returnType="boolean"
attribute in the
cffunction
tag, as in the following
example. When a Flash application calls this ColdFusion function as a service, the function
returns a valid Boolean value of
true
to Flash.
<cffunction name="getBool" access="remote" returntype="boolean">
<cfset foo = True>
<cfreturn foo>
</cffunction>