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

Home > Articles > Design > Adobe Creative Suite

Flash Usability, Part 3: Building the Web Page

Continue your four-part lesson in preserving the text size button's functionality when working with Flash by building the HTML page for your movie in Part 3
Like this article? We recommend

When designing any Web page, its recommended that you have as many different Web browsers at your disposal as possible so that you can adequately test your page for your different users. It's also nice to have at least a Macintosh machine and a Windows machine with those various browsers installed so that you can be sure your pages work across the major platforms. At the least, it's good to have a friend you can bother who has the other platform so that you can send files to test and take screenshots of.

Internet Explorer 5 and Up

The first target browser is Microsoft Internet Explorer, or IE. IE makes up the largest percentage of browsers on the Web, and you can safely assume that a large majority of users reaching your Web site will be using IE. Because most of the popular browsers render things differently on the page, it is necessary for you to "sniff" out the browser so that you can easily target that browser with specific JavaScript.

Open your favorite text editor and create a simple Web page called sizeGetter.html. Enter this HTML to start:

<html>
<head>
  <title>text size getter</title>

</head>
<body text="#000000" topmargin="0" leftmargin="0" marginwidth="0" 
marginheight="0">


</body>
</html>

Now, just below the TITLE tag, paste WebReference.com's latest JavaScript Sniffer code. This code will be used to determine the browser, version, and platform of your users and help you to write code that handles each browser case correctly. Because this is a fairly long script, we will not display it in this article.

<head>
  <title>text size getter</title>
  <script language="JavaScript">
  <!-- ===== Begin WebReference.com JavaScript Sniffer
  // code goes here...
  // ======= End WebReference.com JavaScript Sniffer -->
  </script>

</head>

After the opening BODY tag, create a DIV element on the page and give it the ID of textSizer:

<div id="textSizer" style="background:#ff0000;margin:0;
font-family:sans-serif;visibility:visible">Test Text</div>

Notice that the DIV element's background color is red. This is simply to make it easy to distinguish on the page. You will also notice that the initial visibility of the DIV element is visible. When you are finished testing, you will change that value to hidden, to keep it from showing to the user.

The text inside the DIV is given the generic font family of sans-serif; in our exploration, the sans-serif fonts gave more accurate readings when the text size was changed in the browser. For example, if the text was sized to the Small setting in IE for Windows, its enclosing DIV would be about 15 pixels tall. If you then set the size to Smallest, the width of the font would change slightly, but the height would remain 15 pixels. With the standard sans-serif font, however, setting the text size to Small yields a 16-pixel-high DIV, and Smallest produces a 15-pixel-high DIV.

Now save and test your page. You should see something similar to that in Figure 1.

Figure 5Figure 1 The DIV element with the enclosed test text.

So far, so good! You can test that the DIV behaves as expected by changing the text size from Medium to Largest. You should notice the DIV's height change with the change of the text. If so, you're ready to move on.

Next you will add another SCRIPT section to your page. This section will contain the functions to determine the size of the DIV as the text size changes.

Just below the ending SCRIPT tag for the JavaScript Sniffer code you pasted in, add this code:

<script language="JavaScript">

function getTextSize()
{
  var returnSize = 0;
  if (is_ie5up) {
   returnSize = document.all["textSizer"].offsetHeight;
  }

  return returnSize;
}

After starting the new SCRIPT section, this code defines a new function, getTextSize(), that uses the is_ie5up variable (made available by the JavaScript Sniffer code) to check to see if the user's browser is IE 5 or better. Then it sets the returnSize variable to the current height of the textSizer DIV using the offsetHeight property. The offsetHeight property returns the actual height, in pixels, of the DIV, which should reflect the size of the text inside it. After the returnSize variable is set, it is returned to the calling function, which you will define next.

Add this code following the getTextSize() function definition:

function checkTextSize()
{
  if (currentTextSize != getTextSize()) {
   currentTextSize = getTextSize();
   document.sizerMovie.height = currentTextSize;
  }
}

Here you define the checkTextSize() function. Its job is to compare the current size of the DIV (using the value returned by getTextSize()) to the variable currentTextSize. If the two values are not the same, the currentTextSize variable is set to the new height of the DIV. Depending on the browser and platform, the Flash movie element on the page (which you will create a little later) gets its height set to the current height of the DIV.

Now add the following code to finish the function definitions:

function initSizer()
{
  if (is_ie5up) {
   window.setInterval("checkTextSize()", 300);
  }
}

var currentTextSize = 19;

</script>

The initSizer() function simply checks to see if the proper browser is available and if it is Internet Explorer 5 or better. If it is, the checkTextSize() function is instructed to check the DIV size repeatedly every 300 milliseconds. This is how you will know that the user has changed the text size.

Finally, you initialize the currentTextSize variable to 19 and close out this SCRIPT section.

For all of this to work, you still need a few things: You need to call the initSizer() function to start the repeating check for the size of the textSizer DIV, and you must embed the sizeGetter Flash movie into the page. Let's start with calling the initSizer() function. Change the BODY tag that you added when creating this page to this:

<body onLoad="initSizer()" text="#000000" topmargin="0" leftmargin="0"
marginwidth="0" marginheight="0">

Now when the page is finished loading in the browser, the checkTextSize() function will be told to repeatedly check the DIV height and compare it to its last known height in the currentTextSize variable.

Next, you will add another SCRIPT section that will assemble the proper OBJECT and EMBED tags for the sizeGetter.swf movie that you created earlier. Add the following the code directly before the HTML that defines the textSizer DIV element:

<script language="JavaScript">

var movieBg = "#cccccc";
var movieWidth = "150";
var movieHeight = 18;
var startHeight = 18;

var objectName = "sizerMovie";
var embedName = "sizerMovie";

if (is_ie5up && is_mac) {
  movieHeight = 17;
  startHeight = 17;
  objectName = "unused";
}

var movieName = "sizeGetter.swf?debug=true&startHeight=" + startHeight;

var htmlOut = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-
444553540000"' +
' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/
swflash.cab#version=6,0,0,0"' +
' width="' + movieWidth + '" height="' + movieHeight + '"' +
' id="' + objectName + '" align="">' +
' <param name="movie" value="' + movieName + '">' +
' <param name="quality" value="high">' +
' <param name="bgcolor" value="' + movieBg + '">' +
' <param name="menu" value="false">' +
' <embed src="' + movieName + '" quality="high" bgcolor="' + movieBg +
 '"' +
' width="' + movieWidth + '" height="' + movieHeight + '"' +
' name="' + embedName + '" align="" menu="false" swliveconnect="true"' +
' type="application/x-shockwave-flash" 
pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>' +
'</object>';

document.write(htmlOut);

</script>

This looks like a bunch of complicated JavaScript, but it's actually very simple. The first four lines in this script set variables that will be used for the sizeGetter movie's background color, width, and height. The startHeight variable is set to 18; this is the standard height of the DIV element in IE for Windows when the text inside it is at its normal (medium) text size setting. This value is passed into the sizeGetter movie via the Query String method.

The objectName and embedName variables are used to hold the identifiers for the OBJECT and EMBED tags that display the Flash movie on the page.

The if statement checks whether the user has an IE 5 or better browser and that he is using a Mac. If this is the case, the movieHeight and startHeight variables are set to slightly smaller numbers. This is because, in IE on the Mac (as well as some of the other browsers on the Mac), the font sizes are slightly smaller than with Windows. The objectName variable also gets changed because IE on the Mac adds both the OBJECT tag and the EMBED tag to the Document Object Model of the page. That is, instead of picking the OBJECT tag (as IE for Windows does) or the EMBED tag (for all other browsers), IE on the Mac makes both available in JavaScript. This causes problems when trying to set the height of the sizerMovie object with the checkTextSize() function that you defined earlier. So, you rename the OBJECT movie as unused because the Mac version of IE actually uses the EMBED tag to display the Flash movie.

The movieName variable holds a string representing the URL of the movie, sizeGetter.swf, and the two variables that will be passed onto the movie: debug and startHeight.

The htmlOut variable is then set to a string that combines the previous variables and the OBJECT and EMBED tags to display the Flash movie properly on the page. The document.write() function then prints the value of the htmlOut variable to the page so that the browser can interpret it as if it was plain HTML. Notice that the value for the ID parameter in the OBJECT code and the value for the NAME parameter in the EMBED code are different. This is important because typically they are kept the same.

Finally, the last line completes the SCRIPT tag.

This code is now finished for IE. Make sure that you save your work! Open the file using IE 5 or better on a Windows machine to see if it all works right.

You should see a wide red rectangle with the sizeGetter Flash movie running inside it (see Figure 2). The height field in the Flash movie should read 18, and the percent field should read 100%. Change the text size to Largest using the text size button in the browser, shown in Figure 3.

Figure 2Figure 2 You should now see the Flash movie and DIV in your browser.

Figure 3Figure 3 Change the text size in Internet Explorer with the text size button.

The text in the DIV and the Flash movie should have become larger, and the two fields in the sizeGetter Flash movie should now display different readings. Compare your results to those in Figure 4.

Figure 4Figure 4 When set to the Largest setting, the text is about 133% larger.

Now try setting the browser text to the Smallest setting. The Flash movie's values should change once again. (See Figure 5.)

Figure 5Figure 5 The Smallest size setting yields text about 83% of its original size.

Now open the file on IE 5 or better on the MacOS. (See Figure 6.)

Figure 6Figure 6 The MacOS version of IE displaying the sizeGetter page.

Change the size of the text in the MacOS version of IE. You should see the Flash sizeGetter movie change just as it did in the Windows version. (See Figure 7.)

Figure 7Figure 7 Changing the text size in Mac IE should change the size of the sizeGetter movie as it did in IE for Windows.

If your results are similar to those in the figures above, then you are finished coding for Internet Explorer on both the Windows and Mac platforms. You are now ready to move on to adding the code necessary for the sizeGetter movie to work in Netscape and Mozilla browsers.

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