Information on how to include ActionScript in your Flash forms, and restrictions and additions to ActionScript that apply to ColdFusion Flash forms are described here. However, information on writing ActionScript is not provided. For details on ActionScript and how you can use it, see the Flash ActionScript 2.0 documentation, including the documents available in the Flash and Flex sections of LiveDocs at www.adobe.com/go/learn_cfu_docs_en.
Using ActionScript code in CFML
You can use ActionScript in the following attribute of tags in CFML Flash format forms:
- Form and control events, such as the onSubmit attribute of the cfform tag, or the onChange and onClick attributes of the cfinput tag. The attribute description on the tag reference pages in the CFML Reference list the event attributes.
Bind expressions, which you can use to set field values. For more information on binding data, see Binding data in Flash forms.Your ActionScript code can be inline in the form attribute specification, you can make a call to a custom function that you define, or you can use the ActionScript includecommand in the attribute specification to get the ActionScript from a .as file. The following example shows a simple Fahrenheit to Celsius converter that does the conversion directly on the client, without requiring the user to submit a form to the ColdFusion server.
<cfform format="flash" width="200" height="150">
<cfinput type="text" name="fahrenheit" label="Fahrenheit" width="100"
<cfinput type="text" name="celsius" label="Celsius" width="100">
<cfinput type="button" name="convert" value="Convert" width="100"
onClick="celsius.text = Math.round((farenheit.text-32)/1.8*10)/10">
Note: You do not use the text property (for example, fieldname.text) to access hidden fields. To access a hidden field, use the format formname.fieldname = 'value'.
Custom ActionScript functions
Custom ActionScript functions are the equivalent of CFML UDFs. You can define your own functions in ColdFusion by using the cfformitem tag with a type attribute value of script, or you can define the functions in an ActionScript (.as) file. Also, ColdFusion includes a small number of predefined custom ActionScript functions that you can use in your Flash form controls.
You can use the following custom functions in the ActionScript for all form controls to reset or submit the form:
You can use the following custom functions in cfgrid tags only to insert and delete rows in the grid:
The following example shows how you can use the two GridData functions to add custom buttons that add and delete rows from a Flash form. These buttons are equivalent to the buttons that ColdFusion creates if you specify insert="yes" and delete="yes" in the cfgrid tag, but they allow you to specify you own button text and placement. This example puts the buttons on the side of the grid, instead of below it and uses longer than standard button labels.
<cfform format="flash" height="265" width="400">