Building an Address Book > Creating the Application Functions > The exitEditMode() Function

 

The exitEditMode() Function

The exitEditMode() function returns the address book to "browse mode". That is, it disables the "contact details" pane, and enables the "address book" pane. The functions that require the exitEditMode() function all relate to the user finishing an edit operation: cancelEditMode(), doAddContact(), doUpdateContact().

The exitEditMode() function performs the following tasks:

Disables the text fields in the "contact details" pane.

Disables the phone type ComboBox in the "contact details" pane.

Enables all components in the "address book" pane.

Removes the "Done" and "Cancel" buttons from the "contact details" pane

The complete listing for exitEditMode() is shown below. Read through the comments to see how it works. Notice that we remove the "Done" and "Cancel" PushButtons from the stage using the standard removeMovieClip() method. Remember that components are movie clips and, with a few minor exceptions, can be controlled as such.

/*
 * Function: exitEditMode()
 *   Desc: Returns the app to its regular state, where
 *         the contact details pane is not editable and the
 *         address book pane is active.
 *   Parameters: None.
 */

function exitEditMode () 
{
  // Turn text fields off.
  for (var i = 0; i < editFields.length; i++) {
    // Make text fields non-editable.
    editFields[i].type = "dynamic";
    editFields[i].selectable = false;

    // Turn off text field highlight.
    editFields[i].background = false;
    editFields[i].border = false;
  } 

  // Disable the phone combo box.
  phoneComboBox_cb.setEnabled(false);

  // Enable the address book components
  addButton_pb.setEnabled(true);
  removeButton_pb.setEnabled(true);
  editButton_pb.setEnabled(true);
  sortAZButton_pb.setEnabled(true);
  sortZAButton_pb.setEnabled(true);
  contactListBox_lb.setEnabled(true);

  // Remove the done/cancel buttons
  doneButton_pb.removeMovieClip();
  cancelButton_pb.removeMovieClip();
}