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.

  1. In Flash, open the file you completed in Create the video screen.
  2. In the Timeline, select the keyframe on Frame 66 of the layer named Options Menu.
  3. Open the Library panel (Window > Library), and drag the button named location_SF_button from the library to the Stage.

    Position the button under the text that reads, in part, "Select your preferred location…"

  4. In the Property inspector, type sf_btn in the Instance Name text box.
  5. Drag the button named location_SJ_button from the library to the Stage and position it directly below the location_SF button.
  6. In the property inspector, type sj_btn in the Instance Name text box.
  7. Repeat step 6 for the two buttons in the library named location_PA and location_BK and give them instance names of pa_btn and bk_btn, respectively.

    The Stage of your application should look something like the following example:



  8. In the Actions panel (Window > Actions), enter the following code:
    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