Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Adobe Creative Suite

This chapter is from the book

Building Peachmail: Address Book Services

Now that Joe has logged in, he needs to add some friends to his address book. Peachmail's Address Book allows a user to add contacts, remove contacts, and send emails to contacts. Let's look at how Flash MX works with the server to provide Peachmail's address book services.

The Front-End: Flash MX

Figure 7.11Figure 7.11 The Peachmail application's main email screen.


Each button on the screen is handled in much the same way as the buttons in the login and registration section—that is, each button executes a handler when it's clicked. Joe wants to add some friends to his address book, so he clicks the Address Book button. This triggers the addressBookHandler(), which simply opens a pop-up browser window to show the Address Book screen.

global.openBrowserWindow = function (url, name, width,
 height) {
   getURL("javascript:void(window.open('" + url + "', '" +
    name + "', 'resizable=0, toolbar=0, menubar=0,
    titlebar=0, status=0, width=" + width + ", height=" +
    height + "'))");
}
addressBookHandler = function () {
   openBrowserWindow("addressBook.html", "addressBook",
     217, 157);
} 

The Address Book screen (Figure 7.12) contains three buttons that enable Joe to add a new address, delete an address, or send an email to a selected email address.

Figure 7.12Figure 7.12 Add a new delete an address, or email from the Address .


Adding a New Address

Clicking the New Address button triggers newAddressHandler(), which opens the New Address screen (Figure 7.13) for adding a new address:

Figure 7.13Figure 7.13 The New Address screen.

When the New Address screen is loaded, it creates a local connection to the Address Book screen so that it can pass back the newly added address. Local connections allow data to be passed between two external .swf files. We'll discuss local connections in more detail at the end of this chapter. For now, let's look at what happens when the Create button is clicked:

createHandler = function () {
   // change the address
   newAddressConnection.send("newAddress", name.text,
    email.text);
   // close this window
   getURL("javascript:void(window.close());");
} 

The handler takes the text from the name and email textfields and sends them to the local connection's newAddress() function – the local connection being the Address Book window – and then it closes itself i.e. the New Address window. The Address Book's newAddress() function looks like this:

newAddressConnection.newAddress = function (name, email) {
   // create the new address
   addAddress(name, email);
} 

The newAddress() function takes the name and email and sends them to addAddress():

addAddress = function (name, email) {
   // make the xml
   addAddressXml = buildAddAddressBookEntryRequest(name,
    email);
   // make the callback
   addAddressCallback = function (name, email) {
     // check for success
     if (wasSuccessful(this.getDocIn())) {
        // get the dataNode
        var dataNode = findDataNode(this.getDocIn());
        // get the id
        var id = dataNode.firstChild.attributes.ID;
        // add the entry addressBook.
        addAddress(name, email, id);
     }
   }
   // send to server with name and email supplied as arguments
   sendToServer(addAddressXml, addAddressCallback, name,
    email);
} 

In this code, the buildAddAddressBookEntryRequest() function creates the XML request for the new entry and the sendToServer() function passes the request to the server for processing. You'll recall this mirrors the create-send-callback method discussed earlier in the login and registration section. What is interesting here is the callback function: it takes the XML result from the server and parses it, and then it calls addressBook. addAddress() to add the new address details to the Address Book's listbox:

addressBook.prototype.addAddress = function (name, email, id) {
   // create a temp object to hold values
   var tempObject = {};
   // store the name
   tempObject.name = name;
   // store the email
   tempObject.email = email;
   // store the id
   tempObject.id = id;
   // add the the addresses array
   this.addresses.push(tempObject);
   // add to the listbox
   this.listbox.addItem(tempObject.name + "(" + tempObject.
    email + ")", this.address.length);
   // store in the ids object
   this.ids[id] = this.listbox.getLength() - 1;
} 

Note how the code calls the addItem() method of Macromedia's listbox component to add the new address to the listbox.

Deleting an Address

Deleting an address involves selecting an address from the listbox and then clicking the Delete Address button. When an item is selected from the listbox, it is marked in the listbox so that it can be retrieved later by the listbox.getSelectedIndex() function. When the Delete Address button handler is called it does the following:

deleteAddressHandler = function () {
   // get the id from the selected address
   var id = addressBook.getSelectedAddress().id;
   // delete the address
   deleteAddress(id);
} 

The addressBook.getSelectedAddress() function returns a record containing the name, text, and id fields of the selected address, using the listbox.getSelectedIndex() function mentioned previously.

addressBook.prototype.getSelectedAddress = function () {
   // get the selected item
   var selected = this.listbox.getSelectedIndex();
   // return the object with the item info
   return this.addresses[selected];
} 

The deleteAddress() function creates an XML request for deleting the address, sends it to the server via sendToServer(), and removes the selected address from the Address Book:

deleteAddress = function (id) {
   // make the xml
   deleteAddressXml = buildDeleteAddressBookEntryRequest(id);
   // send the xml
   sendToServer(deleteAddressXml);
   // delete from the address book
   addressBook.deleteAddress(id);
} 

The final step of the delete address method is addressBook.deleteAddress(), which removes the address from the Address Book's listbox:

addressBook.prototype.deleteAddress = function (id) {
   // get the index from the ids object
   var index = this.ids[id];
   // remove from the listbox
   this.listbox.removeItemAt(index);
} 

Sending Email

To send email, the user must first select an address from the Address Book listbox and then click the Send Email button.

sendEmailHandler = function () {
   // get the current email
   var email = addressBook.getSelectedAddress().email;
   // open the compose window
   openCompose(email);
} 

sendEmailHandler() passes the selected address to openCompose(), which handles the creation of the local connection to the Compose screen and the opening of the Compose screen with the selected email address.

openCompose = function (to, subject, message) {
   // create a connection to the compose window
   composeConnection = new popupConnection("compose", false);
   // set the email text fiels contents
   composeConnection.send("setVariable", "to", "text", to);
   // set the subject contents
   composeConnection.send("setVariable", "subject", "text",
    subject);
   // set the message contents
   composeConnection.send("setVariable", "message", "text",
    message);
   // close the connection after everything is sent
   composeConnection.onFinishQueue = function () {
     // close the connection
     this.close();
   }
   // open the compose window
   openBrowserWindow("compose.html", "compose", 550, 400);
} 

The Compose screen (Figure 7.14) appears and the user is given the capability to fill in the textfields and click Send (or Cancel, if he changes his mind).

Figure 7.14Figure 7.14 The Peachmail Compose screen.

The Send button's handler looks like this:

sendHandler = function () {
   // make the xml doc
   var sendMsgXml = buildSendMessageRequest(to.text,
    subject.text, message.text);
   // create the callback
   sendMsgCallback = function () {
     // close the window
     getURL("javascript: void(window.close());");
   }
   // send it to the server
   sendToServer(sendMsgXml, sendMsgCallback);
} 

You'll notice this handler does nothing more than create and send the XML request to the server, and then its callback closes the window. The server handles the work of sending the message to the specified recipient.

The Back-End: Java

Similar to the server handling in the login and registration, the server handling for the address book services consists of taking an XML document, processing the respective request, and firing back a response indicating whether the processing was successful. In adding an address, the processing includes updating the database with the new address. In deleting an address the processing includes removing an address from the database. Finally, in sending the email, the server is responsible for delivering the message to the recipient.

Processing the Add Address Request

When Joe adds an address to his Address Book, this is an example of what he would send to the server:

<Request>
   <TransactionType>AddAddressBookEntry</TransactionType>
   <Data>
     <Entry>
        <Name>Lara</Name>
        <Email>lara@iamlara.com</Email>
     </Entry>
   </Data>
</Request> 

This is a typical response returned by the server if the server were added the address to the database successfully:

<Response>
   <Status>Success</Status>
   <Data>
     <Entry ID="456" />
   </Data>
</Response> 

and unsuccessfully:

<Response>
   <Status>Error</Status>
   <Data>
     <Message>The address did not add successfully</Message>
   </Data>
</Response> 

Processing the Delete Address Request

Let's say Joe successfully added a friend to his Address Book, but realizing he made an error in the email address, he decides to delete the address. The XML request would look like this:

<Request>
   <TransactionType>DeleteAddressBookEntry</TransactionType>
   <Data>
     <Entry ID="56" />
   </Data>
</Request> 

On a successful deletion of the address from the database, the server would return this to Flash:

<Response> 
   <Status>Success</Status> 
   <Data> 
     <Message>The transaction completed successfully
      </Message>
   </Data>
</Response> 

And on an unsuccessful deletion:

<Response>
   <Status>Error</Status>
   <Data>
     <Message>The address did not delete successfully
      </Message>
   </Data>
</Response> 

Processing the Send Email Request

When Joe decides to send an email, the XML request looks like this:

<Request>
   <TransactionType>SendMsg</TransactionType>
   <Data>
     <Addressee>lara@iamlara.com</Addressee>
     <Subject>curious</Subject>
    <Body>Lara, do you miss me? Curious, Joe</Body>
   </Data>
</Request> 

The following is an example of the XML response if the server successfully delivers the message to the recipient:

<Response>
   <Status>Success</Status>
   <Data>
     <Message>The transaction completed successfully
      </Message>
   </Data>
</Response> 

And unsuccessfully:

<Response>
   <Status>Error</Status>
   <Data>
     <Message>The email failed to send</Message>
   </Data>
</Response> 

The Database

On Joe's add address request, the server adds a record to the AddressBookEntries table containing Joe's userID, the new name, and the new email address. The delete address request removes the specified record from the Address-BookEntries table. Finally, the send email request saves the message into the Messages table.

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Peachpit products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.peachpit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020