User Guide

40 Chapter 2: Creating an Application with Components (Flash Professional Only)
checkboxListener.click = function(evt:Object) {
if (evt.target.selected) {
thisChild2.shippingFirstName_ti.text =
thisChild1.billingFirstName_ti.text;
thisChild2.shippingLastName_ti.text =
thisChild1.billingLastName_ti.text;
thisChild2.shippingCountry_ti.text = thisChild1.billingCountry_ti.text;
thisChild2.shippingProvince_ti.text =
thisChild1.billingProvince_ti.text;
thisChild2.shippingCity_ti.text = thisChild1.billingCity_ti.text;
thisChild2.shippingPostal_ti.text = thisChild1.billingPostal_ti.text;
}
};
thisChild2.sameAsBilling_ch.addEventListener("click", checkboxListener);
The first two lines of code are similar to the code for creating the Billing Information child:
you create an instance of the
checkout2_mc movie clip symbol, with the instance name
child2_mc and the label “2. Shipping Information”. The second line of code creates a shortcut
to an embedded ScrollPane component instance.
Beginning with the third line of code, you add an event listener to the CheckBox instance. If
the user clicks the check box, the shipping information uses the data the user entered in the
Billing Information pane.
6.
Next, create a third child for the Accordion instance, for credit card information:
// define the third Accordion child
var child3 = checkout_acc.createChild("checkout3_mc", "child3_mc",
{label:"3. Credit Card Information"});
var thisChild3 = child3.checkout3_sp.spContentHolder;
7.
Add this code to create ComboBox instances for the credit card month, year, and type, and
populate each with a statically defined array:
/* set the values in the three ComboBox instances on the Stage:
ccMonth_cb, ccYear_cb and ccType_cb */
thisChild3.ccMonth_cb.labels = ["01", "02", "03", "04", "05", "06", "07",
"08", "09", "10", "11", "12"];
thisChild3.ccYear_cb.labels = [2004, 2005, 2006, 2007, 2008, 2009, 2010];
thisChild3.ccType_cb.labels = ["VISA", "MasterCard", "American Express",
"Diners Club"];
8.
Finally, add the following code to add event listeners to the Checkout button and the Back
button. When the user clicks the Checkout button, the listener object copies the form fields
from the Billing, Shipping, and Credit Card Information panes into a LoadVars object that is
sent to the server. (The LoadVars class lets you send all the variables in an object to a specified
URL.) When the user clicks the Back button, the application returns to the main screen.
/* Create a listener for the checkout_button Button instance.
This listener sends all the form variables to the server when the user clicks
the Checkout button. */
var checkoutListener:Object = new Object();
checkoutListener.click = function(evt:Object);
evt.target.enabled = false;
/* Create two LoadVars object instances, which send variables to
and receive results from the remote server. */