Flash CS3 Documentation |
|||
| Getting Started with Flash Lite 2.x > Tutorial: Creating a Flash Lite Application > Create the application > Create the set location screen | |||
In this section, you'll create a new screen that lets the user select which of the four restaurant locations they want to call for reservations. The location the user selects on this screen determines the number that's dialed when they select Reservations on the application's home screen.
The first time the user starts the application and selects Reservations on the home screen, the application takes them to the set location screen where they can select a location. Subsequently, when the user selects Reservations, the application immediately dials the default restaurant location's number. The application uses a shared object to save the location that the user selected between sessions.
Position the button under the text that reads, in part, "Select your preferred location…"
The Stage of your application should look something like the following example:
stop ();
fscommand2 ("SetSoftKeys", "Save", "Cancel");
showCurrentLocation();
//
// Soft key event handler code
//
Key.removeListener (myListener);
var myListener:Object = new Object ();
myListener.onKeyDown = function () {
var keyCode = Key.getCode ();
if (keyCode == ExtendedKey.SOFT1) {
// Save location:
saveNewLocation ();
gotoAndPlay ("home");
}
else if (keyCode == ExtendedKey.SOFT2) {
// Cancel operation, go back to home screen:
gotoAndPlay ("home");
}
};
Key.addListener (myListener);
//
// Function: saveNewLocation().
//
function saveNewLocation () {
// Determine which button (location) the user selected:
var selectedButton = Selection.getFocus ();
switch (selectedButton._name) {
case "_level0.sf_btn" :
// User selected San Francisco.
location_so.data.phoneNumber = "415-555-1212";
break;
case "_level0.sj_btn" :
// User selected San Jose.
location_so.data.phoneNumber = "408-555-1212";
break;
case "_level0.bk_btn" :
// User selected Berkeley.
location_so.data.phoneNumber = "510-555-1212";
break;
case "_level0.pa_btn" :
// User selected Palo Alto.
location_so.data.phoneNumber = "650-555-1212";
break;
}
}
//
// Function: showCurrentLocation().
//
function showCurrentLocation() {
// Retrieve phone number stored in shared object:
var phoneNumber:String = location_so.data.phoneNumber;
// Extract area code from phone number:
var areaCode:String = phoneNumber.substring (0, 3);
// Based on area code, set selection focus
// to corresponding button item:
switch (areaCode) {
case "415" :
Selection.setFocus (_level0.sf_btn);
break;
case "408" :
Selection.setFocus (_level0.sj_btn);
break;
case "510" :
Selection.setFocus (_level0.bk_btn);
break;
case "650" :
Selection.setFocus (_level0.pa_btn);
break;
}
}
Flash CS3