Sending Data from Flash to ColdFusion
The Flash movie is nearly complete. The only remaining task is to have the Finish button load the ColdFusion page and send the data to it.
1. | Open dante_quiz.fla in Flash. Click Frame 40 of the actions layer and open the Actions panel. |
You'll see the final script in the movie. In each of the four preceding scripts, after incrementing the score (if appropriate), the script used gotoAndStop() to advance to the next screen. Question 5, however, is the last screen. Rather than advancing to a new screen, you want to load dante_quiz_results.cfm.
2. | Replace the comment "// Insert code here to send data to ColdFusion script" with the following code. getURL("dante_quiz_results.cfm"); |
The getURL() behaves much like the <a> tag i227: it opens a new page in the browser.[View full size image]

getURL("dante_quiz_results.cfm?score=5&username=osiris@allectomedia.com");The problem is that you can't hard-code the values of the score variable ("5") and the username variable ("osiris@allectomedia.com"). You'll need to have Flash insert those values on the fly. Earlier, faced with the same challenge in a ColdFusion page, you used <cfoutput> to solve the problem. Obviously, <cfoutput> is not available in Flash. But an equivalent is.
3. | Revise the getURL() line as follows: getURL("dante_quiz_results.cfm?score=" + score + "&username=" + username); |
Text inside quotation marks is ignored by Flash, which simply passes that text as is. However, the text outside the quotation marks is evaluated by Flash. The + symbol between the text strings in quotes and the variable names outside the quotes are used to glue the pieces together; the programming term for this is concatenation. Thus, if the current value of score is 3, and the current value of username is rory@frogjuice.com, this line will be converted to the following, and will be sent as a request to the server.
getURL(dante_quiz_results.cfm?score=3&username=rory@frogjuice.com)[View full size image]

4. | Create a SWF (Control > Test Movie), and then close the movie after it appears. In Dreamweaver, find the dante_quiz.swf in the flash folder (within the Files panel) and upload it to the remote server. Click dante_quiz_login.cfm and press F12 (Windows) or Option+F12 (Macintosh). Complete the quiz, and then click the Finish button. |
When you choose Control > Test Movie, you create a new version of the SWF file, complete with the new code. But you can't really test the movie in the Flash environment, so close it right away and go to Dreamweaver.When you're finished taking the quiz, you should see dante_quiz_results.cfm. This page has nothing on it yet, beyond the placeholder text. But that doesn't matter; you'll fix that soon enough. Most importantly, notice in the address bar of the browser that the username and score variables have been passed into the URL. Because ColdFusion can see querystrings like this, you'll be able to grab that data and make use of it.[View full size image]

5. | Save and close dante_quiz.fla. |
Now it's time to return to Dreamweaver.