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

Home > Articles > Design > Adobe Creative Suite

This chapter is from the book

ShowThreads, ShowMessages, Frames 20 and 30

The display of topics, threads, and messages (Figure 3.8 and Figure 3.9) are almost identical in their code implementation. Please go ahead and peruse the ActionScript that enables their functionality (Frame 20, Frame 30). You will find the code for those functions is very similar to that of ShowTopics (frame 10). The ScrollPane and text formatting again reigns supreme in the data display.

Figure 3.8Figure 3.8 User can select a thread.


Figure 3.9Figure 3.9 The display of threads and messages is very similar in ActionScript as the display of topics.

We'll move ahead in the FLA to frame 40 where a user can choose to log in (if he's already registered with the message board system.) A login attempt without a previous registration simply produces an error (and the system displays this error).

Login, Frame 40

On frame 40 ("Login"), you'll find a login panel on the Stage composed of two input fields: Username and Password (Figure 3.10). Notice that the text fields are not associated directly with variable names but with variable name instances. Remember, text fields can now be treated as movie clips.

Figure 3.10Figure 3.10 The Login process involves an interface panel with two input fields.


Several functions are defined here on frame 40: loginUser(), parseLoginResults(), and buildLoginTransaction(username, password).

There is a button to submit (to process the entered data), and the code on this button is as follows:

on(press) { 
      // Handle sending the login information
      loginUser(); 
} 

On frame 40 itself, you'll find the code that defines the loginUser function and the ActionScript to handle the validation of the information submitted. After a proper login has taken place, the user is notified of a proper login and is then sent to the topics view ("ShowTopics"). If the user enters information that does not match data in the database, the message board gives the user an error message. The commented code follows:

// loginUser function
// This function is used to log the user into the chat
function loginUser() {
     // build the login transaction
     var loginRequest = buildLoginTransaction(username.text,
password.text); // this goes at the end of the preceding¨ 
code line // set the document to send to the server
     sd.setDocOut(loginRequest);
     // set the document you want to contain the response
     sd.setDocIn(new XML());
     // set the call back for when its done
     sd.onLoad = parseLoginResults;
     // execute it
     sd.execute();
} // end loginUser function

// parseLoginResults function
// This function is used to parse the login
// results from the server
function parseLoginResults() {
     // Get the data from the ServerData object
     var dataIn = this.getDocIn();
     // if the transaction worked or not
     if(!wasSuccessful(dataIn)) {
          // Attach the error panel
          _root.attachMovie("ErrorPanel", "loginErrorPanel",
errorPanelDepth);// this goes at the end of the preceding¨ code line
          // Configure the panel
          loginErrorPanel.setMessage(errorMessage);
          loginErrorPanel.centerClip();
          // Return out of this function
          return;
     } // end wasSuccessful() if statement

     // Attach the message panel
     _root.attachMovie("MessagePanel", "loginMessagePanel",
messagePanelDepth);// this goes at the end of the preceding¨ code line
     // Configure the panel
     loginMessagePanel.setMessage("You have logged in¨ sucessfully.
Press 'OK' to contiue");// this goes at the end of the¨ preceding
// code line
     loginMessagePanel.setButtonText("OK");
     loginMessagePanel.centerClip();
     // Redirect the user when the panel is closed
     loginMessagePanel.messagePanelClose = function() {
          gotoAndPlay("ShowTopics");
     }
} // end parseLoginResults function

// buildLoginTransaction function
// This function creates the XML document for a new user
function buildLoginTransaction(username, password) {
     // Build a basic 'Create User' transaction
     var createUserRequest = buildBaseRequest("Login");
     // Get the data node
     var dataNode = findDataNode(createUserRequest);

     // Username XML code
     // Create the Username node
     var usernameNode = createUserRequest.createElement¨ ("Username");
     // Create the Username text node
     var usernameValue = createUserRequest.createTextNode¨ (username);
     // Append the usernameValue node to the usernameNode
     usernameNode.appendChild(usernameValue);
     // Append the usernameNode to the dataNode node
     dataNode.appendChild(usernameNode);

     // Password XML code
     // Create the Password node
     var passwordNode = createUserRequest.createElement¨ ("Password"); 80
     // Create the Password text node
     var passwordValue = createUserRequest.createTextNode¨ (password);
     // Append the passwordValue node to the passwordNode
     passwordNode.appendChild(passwordValue);
     // Append the passwordNode to the dataNode node
     dataNode.appendChild(passwordNode);
     // return the finished XML document
     return createUserRequest;

} // end buildLoginTransaction function

NewMessage, Frame 60

In order to get your information into the database to participate, the NewMessage part of the application (Figure 3.11) will collect your subject line and body message. If you have not logged in to the system, trying to start a new thread or reply to a post will result in an error message letting you know that you have forgotten to login. If you never registered, it would be time to do so.

Figure 3.11Figure 3.11 The NewMessage module in the message board application.

Several functions are defined at this point: postMessage(), parsePost MessageResults(), and buildPostMessageTransaction(subject, body). postMessage() is the main function in this section, and the other two functions are nested within it, so that upon calling postMessage(), all functions execute and process.

Please pay special attention to the commenting in the ActionScript because it really goes a long way guiding you to its functionality.

The following code is on the submit button:

on(press) {
     // Post the message
     postMessage();
}

The ActionScript for the posting of a new message (on frame 60):

// postMessage function
// This function is used to log the user into the chat
function postMessage() {
     // build the postMessage transaction
     var loginRequest = buildPostMessageTransaction¨ (messageTitle.text,
messageBody.text);// this goes at the end of the preceding¨ code line
     // set the document to send to the server
     sd.setDocOut(loginRequest);
     // set the document you want to contain the response
     sd.setDocIn(new XML());
     // set the call back for when its done
     sd.onLoad = parsePostMessageResults;
     // execute it
     sd.execute();
} // end postMessage function

// parsePostMessageResults function
// This function is used to parse the post message
// results from the server
function parsePostMessageResults() {

     // Get the data from the ServerData object
     var dataIn = this.getDocIn();
     // if the transaction worked or not
     if(!wasSuccessful(dataIn)) { 82
          // Attach the error panel
          _root.attachMovie("ErrorPanel", "messageErrorPanel",
errorPanelDepth);// this goes at the end of the preceding¨ code line
          // Configure the panel
          messageErrorPanel.setMessage(errorMessage);
          messageErrorPanel.centerClip();
          // Return out of this function
          return;
     } // end wasSuccessful() if statement
     // Attach the message panel
     _root.attachMovie("MessagePanel", "messageMessagePanel",
messagePanelDepth);// this goes at the end of the preceding¨ code line
     // Configure the panel
     messageMessagePanel.setMessage("Your message has been¨ posted
sucessfully.\nPress 'OK' to contiue");// this goes at the¨ end of the
// preceding code line
     messageMessagePanel.setButtonText("OK");
     messageMessagePanel.centerClip();
     // Redirect the user when the panel is closed
     messageMessagePanel.messagePanelClose = function() {
          gotoAndPlay("ShowThreads");
     }
} // end parsePostMessageResults function

// buildPostMessageTransaction function
// This function creates the XML document for a new message
function buildPostMessageTransaction(subject, body) {
     // Build a basic 'Post Message' transaction
     var postMessageRequest = buildBaseRequest("PostMessage");
     // Get the data node
     var dataNode = findDataNode(postMessageRequest);
     // Subject XML code
     // Create the usernameNode
     var subjectNode = postMessageRequest.createElement¨ ("Subject");
// Create the Subject text node
     var subjectValue = postMessageRequest.createTextNode¨ (subject);
// Append the subjectValue node to the subjectNode
     subjectNode.appendChild(subjectValue);

     // Body XML code
     // Create the Body node
     var bodyNode = postMessageRequest.createElement("Body");

     // Create the Body text node
     var bodyValue = postMessageRequest.createTextNode(body);

     // Append the bodyValue node to the bodyNode
     bodyNode.appendChild(bodyValue);

     // Message XML code
     // create the messageNode
     var messageNode = postMessageRequest.createElement¨ ("Message");

     // Add the attributes
     messageNode.attributes.TopicID = topicID;
     messageNode.attributes.ThreadID = threadID;

     // Append the subjectNode to the messageNode
     messageNode.appendChild(subjectNode);

     // Append the bodyNode to the messageNode
     messageNode.appendChild(bodyNode);

     // Append the messageNode to the dataNode
     dataNode.appendChild(messageNode);

     // return the finished XML document
     return postMessageRequest;

} // end buildPostMessageTransaction function

Please refer to the backend process diagram (Figure 3.2) at the beginning of this chapter. You can see how the postMessageRequest transaction is processed. For that matter, having the diagram handy will help you understand the processing of different types of requests throughout the entire system.

Register, Frame 70

In order to properly log in, a user needs to first register an account (Figure 3.12) within the message board system. This allows for the entry of a user-name and password, which are stored in the database for future queries. Registration also requires a proper email address to be entered, and a response to an input text box asking whether the email address should be available to others viewing posts and so forth made by this registrant. For now the field should contain "Yes" or "No"—you could provide radio buttons, or similar selection methods for this if you wish to customize the application. Users who don't register or log in receive an error message (Figure 3.13).

Figure 3.12Figure 3.12 A Flash form collects data and registers a new to allow for the posting of threads and replies.


Figure 3.13Figure 3.13 A user who hasn't registered or logged in gets an error message when trying to interact with the message board system.

The following code is used to register a user in the database. This process involves several functions that run sequentially. The first step is to call buildCreateUserTransaction and pass in the needed data. This function builds the XML document needed to register a user. Once we have that document, we send it to the server and use parseRegistrationResults to determine whether the transaction was successful. At this point, the application is able to proceed.

// registerUser function
// This function will register a user with the server
function registerUser() {

     // Build the create user transaction
     var createUserRequest = buildCreateUserTransaction¨ (username.text,
password.text, email.text, showEmail.text);// this goes at¨ the end
// of the preceding code line

     // set the document to send to the server
     sd.setDocOut(createUserRequest);

     // set the document you want to contain the response
     sd.setDocIn(new XML());

     // set the call back for when its done
     sd.onLoad = parseRegistrationResults;

     // execute it
     sd.execute();

} // end registerUser function

// parseRegistrationResults function
// This function is used to parse the registration
// results from the server
function parseRegistrationResults() {

     // Get the data from the ServerData object
     var dataIn = this.getDocIn();

     // if the transaction worked or not
     if(!wasSuccessful(dataIn)) {

          // Attach the error panel
          _root.attachMovie("ErrorPanel",
"registerErrorPanel",
errorPanelDepth);// this goes at the end of the preceding¨ code line

          // Configure the panel
          registerErrorPanel.setMessage(errorMessage);
          registerErrorPanel.centerClip();

          // Return out of this function
          return;

     } // end wasSuccessful() if statement

     // Attach the message panel
     _root.attachMovie("MessagePanel",
"registerMessagePanel",
messagePanelDepth);// this goes at the end of the preceding¨ code line

     // Configure the panel
     registerMessagePanel.setMessage("You have registed a new¨ account
sucessfully. Press 'Log In' to contiue");// this goes at¨ the end of
// the preceding code line
     registerMessagePanel.setButtonText("Log In");
     registerMessagePanel.centerClip();

     // Redirect the user when the panel is closed
     registerMessagePanel.messagePanelClose = function() {
          gotoAndPlay("Login");
     }

} // end parseRegistrationResults function

// buildCreateUserTransaction function
// This function creates the XML document for a new user
function buildCreateUserTransaction(username, password,¨ email,
showEmail) {// this goes at the end of the preceding code¨ line

     // Build a basic 'Create User' transaction
     var createUserRequest = buildBaseRequest("CreateUser");

     // Get the data node
     var dataNode = findDataNode(createUserRequest);

     // Username XML code
     // Create the Username node
     var usernameNode =
createUserRequest.createElement("Username");

     // Create the Username text node
     var usernameValue = createUserRequest.createTextNode¨ (username); 

     // Append the usernameValue node to the usernameNode
     usernameNode.appendChild(usernameValue);

     // Append the usernameNode to the dataNode node
     dataNode.appendChild(usernameNode);

     // Password XML code
     // Create the Password node
     var passwordNode = createUserRequest.createElement¨ ("Password");

     // Create the Password text node
     var passwordValue = createUserRequest.createTextNode¨ (password);

     // Append the passwordValue node to the passwordNode
     passwordNode.appendChild(passwordValue);

     // Append the passwordNode to the dataNode node
     dataNode.appendChild(passwordNode);

     // Email XML code
     // Create the Email node
     var emailNode = createUserRequest.createElement¨ ("Email");

     // Create the Email text node
     var emailValue = createUserRequest.createTextNode(email);

     // Append the emailValue node to the emailNode
     emailNode.appendChild(emailValue);

     // Append the emailNode to the dataNode node
     dataNode.appendChild(emailNode);

     // ShowEmail XML code
     // Create the Email node
     var showEmailNode = createUserRequest.createElement¨ ("ShowEmail");

     // Create the Email text node
     var showEmailValue = createUserRequest.createTextNode¨ (showEmail);

     // Append the showEmailValue node to the showEmailNode
     showEmailNode.appendChild(showEmailValue);

     // Append the showEmailNode to the dataNode node
     dataNode.appendChild(showEmailNode);

     // return the finished XML document
     return createUserRequest;

} // end buildCreateUserTransaction function

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