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

Home > Articles > Design > Adobe Creative Suite

This chapter is from the book

Creating Standard Components for Devices

No matter what you are creating for devices, at some point, you will need a "standard" component of some sort. Whether you need a radio button, checkbox, slider, or drop-down menu, creating and perfecting the infernal little thing will take up too much of your time. Any time you have to reinvent the wheel, it's a painful experience; thankfully, you don't have to do it now. On the web site for this book, (http://www.flashenabled.com) is a full set of components that are made just for devices. Download them now and then come back and learn all about how to use them!

Understanding Smart Clips

All the other components you'll create for devices are Flash 5 smart clips. If you are unfamiliar with smart clips, the idea behind them is actually quite simple. Smart clips are just normal movie clips that have a visual interface for setting variables that live within them. Although they are simple, they provide an extremely easy mechanism for configuring reusable components.

Smart clips do have drawbacks, though. Specifically, methods that are defined within a smart clip are not immediately available in their parent's timeline. This is because a smart clip's code runs after that of its parent timeline. As long as you keep this limitation in mind and don't try to access methods within a smart clip immediately, you shouldn't have trouble.

For more information on creating and working with smart clips, check out the Flash Exchange at http://www.macromedia.com/exchange/flash/.

Checkboxes

The checkbox control provides a simple method for allowing users to select Boolean values (see Figure 3.1). It's easy for both users and developers.

Figure 3.1 A simple checkbox control in action.

All you need to do to use the checkbox control is place an instance of the DeviceCheckBox movie clip on the stage and then bring up the Clip Parameters panel. Here you see that the checkbox has three parameters: varName, initialState, and enabled. The first parameter, varName, is the name of the variable that this checkbox sets. This variable lives in the same timeline that houses the checkbox component. The second parameter, as it suggests, sets the initial state of the checkbox—on or off. The final parameter, enabled, allows you to decide if the component should be immediately usable or if it will have to be enabled in some way before the user can modify it.

After you have set these parameters, you're done! There's nothing else you have to do to use the checkbox. However, there are a few additional methods and callbacks that the component supports (see Figure 3.2).

First, there's the setVar method. This method supports a single parameter, a string. When you call this method, you are changing what variable is tied to the checkbox.

Next, there's the setState method, which gets passed a single parameter, a Boolean value (true or false). This method allows you to change the state of the checkbox at any time without requiring the user to intervene.

Finally, there are the enable and disable methods. These methods do exactly what you might think they do: They enable and disable the checkbox.

Figure 3.2 The Clip Parameters panel for the checkbox smart clip.

Along with these methods, I mentioned that the checkbox also has a couple of callbacks. Callbacks are methods that you can overwrite to allow you to easily capture the point at which a particular event occurs. In the case of the checkbox, there's a callback for onChecked and another for onUnchecked.

To see how these work, let's look at an example. Let's say that you already have a checkbox on your stage and it has an instance name of checkbox01. Let's also say that when this checkbox is checked, you want a movie clip named ball to appear; when it's unchecked, you want the movie clip to disappear. To do this, you would have the following code on your main timeline:

checkbox01.onChecked = function(){
   _parent.ball._visible = true;
}
checkbox01.onUnChecked = function(){
   _parent.ball._visible = false;
}

What's happening here is that you are overriding the onChecked and onUnChecked methods of your checkbox movie clip. That is, the checkbox assumes those methods are in place and calls them automatically. By redefining them with your own code, you are making Flash run your custom code each time it calls those methods.

Radio Buttons

Radio buttons allow users to choose a single option but still see all the options available to them (see Figure 3.3). Actually, calling it the radio button component is a bit of a misnomer. This is because the actual component is the radio button group because there's not a whole lot you can do with a single radio button!

Figure 3.3 A group of radio buttons in action.

However, if the component were to be the radio button group, then you would have to define the layout of the individual buttons within the Clip Parameters panel—not exactly WYSIWYG. Because the component is actually just a piece of a component, there are a few strange things you will need to get used to when using the radio button.

Each radio button instance that you drag to the stage (the DeviceRadioButton movie clip) has a number of properties that you need to set in the Clip Parameters panel (see Figure 3.4). These parameters are groupName, value, initialState, and enabled.

Figure 3.4 The Clip Parameters panel for the radio button smart clip.

The groupName parameter sets the name of the group to which this radio button belongs. It is actually the name of an object that will be created in the timeline to handle the group as a whole, but we'll get into that later.

The value parameter is the value of that particular radio button. The actual type of this value will always be a string, so if you set this to be a number, be sure that the function that will be reading the values changes the type appropriately.

The initialState parameter determines if the radio button will be on or off by default. Keep in mind that if you have multiple radio buttons, their initialState should be set to true. Only the last one will actually stay true because radio button groups can only have one radio button on at a time.

Finally, the enabled parameter sets whether the group to which this radio button belongs is enabled by default. Notice that we are talking about the whole group and not an individual button; therefore, like the initialState parameter, it's only the last button in the group that can actually change this parameter.

Radio buttons also support a single method: setState. You pass setState a single Boolean parameter, which represents the state to which you want to change the radio button.

As you learned earlier, the radio button component creates a radio button group object for working with the group as a whole. However, again due to some shortcomings with the smart clip architecture, you need to create the group yourself if you want to be able to use it immediately.

For example, if you had a group of radio buttons on the main timeline with their group all set to myGroup, you would probably want to have the following code in your main timeline:

myGroup = new Object(); 

After that line, you can use some of the special functionality of the radio button group object.

The radio button group object is where you can enable or disable the group, where the current value of the group lives, and where a special callback lives that lets you capture when a radio button is selected.

Just like the checkbox component, the radio button group supports both enable and disable methods. The most interesting parts of the radio button group are its value property and its onRadio callback. The value property of a radio button group always contains the current value of the group. (Remember: The value of the group depends on the values you set for each radio button.) The onRadio callback is called any time a radio button in the group is selected. It is passed the value of the button that is selected.

For example, if you just wanted to trace out the value of the myGroup radio button group, you would have the following code in your main timeline:

myGroup = new Object();
myGroup.onRadio = function(value){
   trace("Radio button group value: "+value);
}

If you ever want to disable the entire radio button group, you can simply use this:

MyGroup.disable();

You might want to do this if the availability of a radio button group is dependent on some external variable. For example, if the user has the sound turned off in an application, he can't choose the default sound for the application.

Sliders

The slider control provides a simple method for allowing users to choose from a range of values. It allows users to drag the slider around or simply click on the location where they want it to be (see Figure 3.5).

Figure 3.5 A slider component in action.

Like the other two previously discussed controls, the slider control is a smart clip and is named DeviceSlider (see Figure 3.6). After you have dragged an instance of it onto the stage, there are a number of parameters you can set for it in the Clip Parameters panel, such as min, max, default, integersOnly, and enabled.

Figure 3.6 The Clip Parameters panel of the slider smart clip.

The min parameter sets the minimum value that the slider can report. Note that this is inclusive; therefore, if you set this to 0, at its lowest point, the slider produces 0 as its value.

The max parameter, as you might have guessed, sets the maximum value that the slider can report. Like the min parameter, the max parameter is inclusive in nature.

The default parameter is the value that the slider will display when it is first shown. The slider will fire off a call to its onSlide callback when it sets this initial value.

Finally, the enabled parameter works just like the enabled parameter in the other components and allows you to specify whether the slider is initially enabled.

Besides these parameters, the slider supports three functions—enable, disable, and setSlider—as well as a callback, onSlide. The enable and disable functions work just like they do in the other components. They allow you to disable and enable the component any time you want.

The setSlider method allows you to set the value of the slider at any time. Note that the value that you pass to setSlider must be within the min and max range you set for the component.

Lastly, onSlide is called any time the slider is moved either by dragging it or by clicking on the slider's gutter. The onSlide method is passed the new value of the slider. In addition, the current value of the slider is always stored in the value property of the component.

If you want to simply capture the current value of a slider component named mySlider and trace it, you would code the following:

mySlider.onSlide = function(value){
   trace("slider value: "+value);
}

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