This tutorial will provide you with a step by step process on how to pass form values from a Flash ActionScript file to a Coldfusion Page using the LoadVars Object.

Many of the tutorials on the internet are completely bogus as they often do not work.

The company I am working for came up with a project that needed Coldfusion and Flash to talk together... After an excruciating week of research, I finally came up with a working solution and I want to share it with you.

The good thing is that, I am also new to ActionScript, so this tutorial will be as simple as possible.

For this application to work you should be using Flash MX and higher, as I am not sure the LoadVars Object syntax is available for earlier versions of Flash.

Also, you should already we familiar with creating forms in Flash. You can use any RDMS database you have, Access, SQL etc. I am using SQL

Table name: TEST
Columns: name_ti, email_ti, state_ti, zip_ti, and Date


1. Open a new Flash Document and create the flash form you see below... Use the 'A' (text tool). Place this entire form on the first frame of the default layer...

Figure 1.0

Text Boxes
In the property Inspector, set the text boxes on the left to 'Input Text', and set the text box on the right to 'Dynamic text',

NOTE: In the property Inspector, provide the instance name of the text boxes... (The instance names I used are shown above inside the text boxes).

Submit Button:
Set the submit button to button, and name this instance bSumit. You can use a Flash component for the button or create your own. I created my own button, but I do not think it matters.

2. Create a new layer for the document and call the layer 'Actions'. We would place all our ActionScript code here. There would be absolutely no code on any layer but this one.

3. Click on the First Frame of the 'action' Layer, then hit F9 to pull up the ActionScript window....

NB: The ActionScript must be on the 1st frame of the Actions Layer. Or, it can be on the corresponding frame as the items on the default layer (labels).... See below....! This tells the ActionScript what items it will be manipulating.....

Figure 2.0

Enter the following code....

//Define function to process form data
function checkUser():Void {

    //Creates an instance of LoadVars to send form data to Coldfusion.
    // creating an Array with LoadVars called dataOut to send the form data as a bulk //to Coldfusion.
    var dataOut:LoadVars = new LoadVars();

    /* The variables below i.e. Fname, .Femail, .Fstate, .Fzip, are variables I made up. I chose the names randomly and simply used the dot.syntax to match them up with the dataOut function created above. These variables will be the once that will correspond to the variables in Coldfusion – This is the link...! */

    dataOut.Fname = name_ti.text;
    dataOut.Femail = email_ti.text;
    dataOut.Fstate = state_ti.text;
    dataOut.Fzip = zip_ti.text;
    //Using send ( ); method to send the data
    dataOut.send("http://www.yourdomain/flash/insert.cfm", "POST");

    /*After the data is sent, we move to the next frame in Flash --- If you have a second frame with a thank you message for example, you can uncomment the code below.*/
    //Nextframe( );

/* On release of the Submit button, the function checkUser(); we created above is called... I added a nifty validation method for the form...*/

bSumit.onRelease = function() {
    if (name_ti.text == "" || email_ti.text == "" || state_ti.text == "" || zip_ti.text == "") {

        // if the form is left empty, this message is displayed in the dynamic text we set //called status_txt.
        status_txt.text = "Please complete the entire form ...";
    } else {
        status_txt = "";

        //invoke function checkUser ( );

Yes we are done. Now for the insert.cfm page....

<!-- Insert Flash variables into the database -->
<!—NOTE: The values you are passing in the VALUES of this SQL statement are the same Values you defined in dataOut.Fname in the ActionScript etc. and so on.

Do not use '#form.Fname#' as you are used to etc. #Fname# is enough. You can use these variables in any way you wish, I choose to insert them into a db table -->

<CFQUERY DATASOURCE="CGM" name="insert">
INSERT INTO Test (      name_ti

<!—Output Message to user. -->

<h1 align="center">
    Thank you for your
    form submission!

Now we are done. This is the best way to use LoadVars Object. I hope this tutorial is helpful.

NOTE: There should not be any problem with different form types such as a drop down list etc. The code will pass any value in the text field.

If you have any questions, feel free to contact me at:
Subject: Flash Coldfusion Tutorial.  (This way, I will know it's a legitimate email and I will not delete it or spam it.

About This Tutorial
Author: Abena Kuttin
Skill Level: Intermediate 
Platforms Tested: CF3
Total Views: 100,427
Submission Date: July 27, 2006
Last Update Date: June 05, 2009
All Tutorials By This Autor: 1
Discuss This Tutorial

Sponsored By...
Mobile App Development (IOS, Android, Cordova, Phonegap, Objective-C, Java) - Austin, Texas Mobile Apps - Touch512, LLC.