User Guide
890 Chapter 3: ColdFusion Functions
An ActionScript-style array does not require you to include the wddx.js file, and creates a variable
that you can use in ActionScript on a Flash format form, for example, in an
onChange attribute.
If the
outputformat parameter is False, setting ASFormat to True causes ToScript to use the
ActionScript shortcut
[] in place of New Array() and the shortcut {} in place of New Object().
Using these shortcuts allows you to pass ActionScript into
cfform attributes without triggering
ActionScript validation. If
ASFormat is False, ToScript generates New Array() and New
Object() in the script.
Example
The following example shows the results of converting a ColdFusion string, array, and query
object to JavaScript variables. It also uses the string and array in JavaScript code.
<h2>ToScript</h2>
<h3>Converting a string variable</h3>
<cfset thisString = "This is a string">
<cfoutput>
<b>The thisString variable in ColdFusion</b><br>
#thisString#<br>
<br>
<strong>The output of ToScript(thisString, "jsVar")</strong><br>
#ToScript(thisString, "jsVar")#<br>
<br>
<strong>In a JavaScript script, convert thisString Variable to JavaScript
and output the resulting variable:</strong><br>
<script type="text/javascript" language="JavaScript">
var #ToScript(thisString, "jsVar")#;
document.write("jsVar in JavaScript is: " + jsVar);
</script>
</cfoutput>
<h3>Converting an array</h3>
<!--- Create and populate a one-dimensional array --->
<cfset myArray=ArrayNew(1)>
<cfloop index="i" from="1" to="4">
<cfset myArray[i]="This is array element" & i>
</cfloop>
<cfoutput>
<b>The ColdFusion myArray Array</b><br>
<!--- Write the contents of the myArray variable in ColdFusion --->
<cfloop index="i" from="1" to="#arrayLen(myArray)#">
myArry[#i#]: #myArray[i]#<br>
</cfloop>
<br>
<strong>The output of ToScript(myArray, "jsArray")</strong><br>
#toScript(myArray, "jsArray")#<br>
<br>
<strong>In JavaScript, convert myArray to a JavaScript variable and write
it's contents</strong><br>
<script type="text/javascript" language="JavaScript">
var #ToScript(myArray, "jsArray")#;
for (i in jsArray)