
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
424
|
Chapter 17: Building a Flash Form
Sending Data to the Server
To send the value of input_txt to echo.pl, we’ll create the custom functions initForm(),
shown in Example 17-1, and submitForm(), shown in Example 17-2. The initForm()
function creates one instance of the LoadVars class to send our data (
dataSender) and
another to receive echo.pl’s response (
dataReceiver). The initForm( ) function also
assigns a callback function to
dataReceiver’s onLoad( ) handler, which executes when
echo.pl’s reply arrives. The callback function displays the reply in the
response clip.
Notice that initForm( ) creates a global variable used to refer to the form’s timeline.
Hence, all our references to the
response clip are fully qualified.
The submitForm( ) function, shown in Example 17-2, gathers the data and transmits
it to echo.pl.
Example 17-1. The initForm( ) function
/*
* Function: initForm( )
* Desc: Creates LoadVars objects for sending and
* receiving data to and from the server.
* Parameters: None.
*/
function initForm ( ) {
// Create a reference to the form timeline.
_global.form_mc = this;
// Create the LoadVars objects.
// One to send...
dataSender = new LoadVars( );
// ...and one to receive.
dataReceiver = new LoadVars( );
// Assign a callback function to the dataReceiver's onLoad handler. ...