Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Flash MX action script bible - Reinhardt R.

Reinhardt R. Flash MX action script bible - Wiley & sons , 2004. - 987 p.
ISBN: 0-7645-4354-7
Download (direct link): macractionscriptbiblefeb2004.pdf
Previous << 1 .. 392 393 394 395 396 397 < 398 > 399 400 401 402 403 404 .. 427 >> Next

Figure 37-1: The layout of the simpleForm001.fla application
4. Add the following code to the Actions layer:
// Add values to the labels. clblEmail.text = "Email:"; clblProducts.text = "Products Owned:";
// Set the data provider for the List component instance. clProducts.dataProvider = [{label: "Flash", data: "f"}, ^ {label: "Dreamweaver", data: "dw"}, ^
{label: "Fireworks", data: "fw"}, ^
{label: "ColdFusion", data: "cf"}, ^
{label: "Freehand", data: "fh"}];
// Sort the items in the List. clProducts.dataProvider.sortItemsBy("label");
// Allow multiple selections. clProducts.multipleSelection = true;
// Create the listener object for the Button. var oListener:Object = new Object(); oListener.click = function(oEvent:Object):Void {
// Get the email and selected products. var sEmail:String = ctiEmail.text; var aProductItems:Array = clProducts.selectedltems; var aProductData:Array = new Array();
// Loop through all the selected products, and append // the data value to the aProductData array. for(var i:Number = 0; i < aProductltems.length; i++) { aProductData.push(aProductItems[i].data);
}
Chapter 37 ♦ Making Flash Forms 877
// Display the values. trace(sEmail + " " + aProductData);
};
cbtSubmit.label = "Submit";
cbtSubmit.addEventListener("click", oListener);
5. Test the movie. Add an e-mail address and select products, and then click the button.
Submitting Form Data
Once you have created a form, the next thing is to actually do something with that form data. This is usually referred to as submitting the form data because typically you submit the data for processing to a server-side script or Web application. The data may then get written to a file or to a database or any number of other types of processing.
Basic Form Data Submitting
Submitting a form usually involves clicking a button of some kind. Although this is not necessary (it could be a timed process, or it could be submitted once the user has made a selection), it is the most common way to submit a form. Therefore, you can choose to use any kind of button-like control such as a Button, MovieClip, or a Button component instance as used in the exercise in the previous section.
Using LoadVars to Send Data
Once a form has been filled out, the next likely step is to actually transmit that data to something, be it a CGI, PHP, or ColdFusion page, as a few examples. If you are sending the data to some such server-side script or application, you have several options. First, take a look at how to send it using a LoadVars object.
In this exercise you’ll use a LoadVars object to submit the data from the form to a script.
1. On the CD-ROM you’ll find PHP and ColdFusion versions of a script called either
asbSubmitFormLoadVars.php or asbSubmitFormLoadVars.cfm. Copy the appropriate script from the CD-ROM to the Web root of the server.
2. Open simpleForm001.fla and save it as submitFormLoadVars001.fla.
3. Modify the code on the Actions layer as follows (changes appear in bold):
clblEmail.text = "Email:"; clblProducts.text = "Products Owned:";
clProducts.dataProvider = [{label: "Flash", data: "f"}, ^
{label: "Dreamweaver", data: "dw"}, ^
{label: "Fireworks", data: "fw"}, ^
{label: "ColdFusion", data: "cf"}, ^
{label: "Freehand", data: "fh"}]; clProducts.dataProvider.sortItemsBy("label"); clProducts.multipleSelection = true; var oListener:Object = new Object();
878 Part X ♦ Creating Flash Applications
oListener.click = function(oEvent:Object):Void { var sEmail:String = ctiEmail.text; var aProductItems:Array = clProducts.selectedItems; var aProductData:Array = new Array(); for(var i:Number = 0; i < aProductItems.length; i++) { aProductData.push(aProductItems[i].data);
}
// Create the submitting LoadVars object. var lvSender:LoadVars = new LoadVars();
// Create the LoadVars object for receipt. var lvReceipt:LoadVars = new LoadVars();
// Define the onLoad() method. lvReceipt.onLoad = function():Void { trace("receipt");
};
// Assign the email and products values to properties on
// the sending LoadVars object.
lvSender.email = sEmail;
lvSender.products = aProductData.toString();
// Send the data to the script. Make sure to use the URL
// that correctly points to the script on your server.
lvSender.sendAndLoad("http://localhost/^ asbFormSubmitLoadVars.php", lvReceipt);
};
cbtSubmit.label = "Submit";
cbtSubmit.addEventListener("click", oListener);
4. Test the movie. Enter some data and then click the button to send the data to the server-side script.
^Note
Using XML to Send Data
Depending on the type of data with which you’re working, XML can be a good choice for sending data from Flash to a server-side script. In this exercise, you’ll modify the Flash application to send XML data to the server-side script.
1. On the CD-ROM are PHP and ColdFusion scripts named asbFormSubmitXML.php and asbFormSubmitXML.cfm, respectively. Choose the appropriate script and copy it to the Web root on your server.
5. A file called asb.txt i s created in the same directory as the server-side script. If you view that file, you can see the entry that was just made.
Previous << 1 .. 392 393 394 395 396 397 < 398 > 399 400 401 402 403 404 .. 427 >> Next