Macromedia Flash8 Bible

Flash 8 includes several User Interface (or UI) components, which provide user interface elements and functionality frequently used by developers. You should be able to find a use for some or all of these components at one time or another. Let's take a look at what each of the core UI components does and how to use them in your movies. After dragging any component instance to your Stage, open up the Property inspector and select the Parameters tab to view the parameters discussed in this section.

Tip 

Most of the V2 components feature the Halo skin, with colors and effects that resemble modern day operating systems' interfaces. Most UI components in Flash 8 will function properly in Flash Player 6 movies. If you're in doubt, simply publish or test your Flash movie as a Flash Player 6 movie and see if the component works as expected. Make sure you set the ActionScript version to ActionScript 2.0 in the Publish Settings as well.

Note 

The Flash MX 2004 and Flash 8 component framework does not use click or change handlers in the same way that V1 components from Flash MX did. Refer to the "Understanding the Listener Event Model for Components" section, later in this chapter, for more information.

The parameters for each component we discuss in the following sections are also the respective names of each component's properties. Note that not all of a component's properties may be exposed in the Property inspector.

Button Component

This component is essentially a standard button with built-in up, over, and down states. The button is designed to resemble an HTML form button (such as a submit button), but with the Halo theme for V2 components. The Button component, shown in Figure 33-7, is very easy to use and can aid in quick development of mockups or be modified to suit more aesthetically inclined productions.

Figure 33-7: The Button component as it appears in a Flash movie at run time

Caution 

Do not confuse a Button component with a Button symbol. The Button component replaces the V1 PushButton component from Flash MX. In this chapter, any reference to Button instance implies a Button component, not a Button symbol.

Parameters

The Button parameters are perhaps some of the easiest to manage. As with other components, you can enter text for the button's label and set a function to execute when the button is pressed.

Caution 

If you use the Property inspector to set the selected parameter to true, the Button instance (unfortunately) will not appear with a selected state when you publish or test the movie. The selected property must be set in ActionScript to work properly.

How it Works

An instance of a Button component can have regular, disabled, or active states, which can be customized graphically. It is a very quick way to add interactivity to your movie. For additional functionality of the button, you will need to write ActionScript using the Button methods.

Tip 

The "click" event is sent to any listeners when a Button component instance is clicked. You can use an on(click) event handler directly on a Button component instance to initiate further actions when the instance is clicked, but adding code to instances on the Stage is generally not accepted as a best practice.

Cross-Reference 

You can find several examples of the Button component throughout many chapters of this book. You can also search for "button component" in the Flash 8 Help panel to find more information on the Button component. If you search for "button component class," you'll find the primary page describing the methods and properties of the Button component.

CheckBox Component

The CheckBox component, as the name implies, is a user interface element that has a selection box next to text. As with HTML form check boxes, the CheckBox component enables you to easily add form options to a Flash movie. The CheckBox component returns a true or false value. If the box is checked, it returns a true value; if not, it returns false. These states are shown in Figure 33-8.

Figure 33-8: A selected (true) check box, left, and a cleared (false) check box, right

Parameters

CheckBox parameters can be changed to customize the default label text and its placement in relation to the check box graphic. You can also set the initial state and have the option of setting a function, executing as soon as the button state changes.

How it Works

The CheckBox component has a hit area that encompasses the check box itself, as well as the label next to it. The width of a CheckBox instance can be transformed to accommodate more text. Added functionality using ActionScript is possible by using the methods, events, and properties of the CheckBox class.

ComboBox Component

The ComboBox component is similar to any standard HTML form drop-down list. When you click the component instance, a list of options appears below the default value in the list. You can also navigate the list using the up-arrow, down-arrow, Page Up, Page Down, Home, and End keys. This component is very useful and essentially has the following two different functionalities:

Figure 33-9: A standard ComboBox instance, shown closed (left) and open (right)

Figure 33-10: An editable ComboBox instance, shown with default display (left) and entered text (right)

Parameters

ComboBox parameters can be changed to set labels and data for each item in the drop-down box, set the top of the pull-down to be a text input box (an editable combo box), and customize how many items are viewable when the arrow is selected.

How it Works

When you click the data or labels field in the Property inspector, you will notice a magnifying glass icon next to the drop-down area. This button, when clicked, opens a Values panel where you can enter the array of values using the + or - buttons.

Tip 

The values for these parameters use a zero-based index, which means the first item in your array is listed as [0].

Functionality can be added using ActionScript, and the ComboBox class's methods, properties, and event handlers can be used with each instance of this component.

List Component

The List component also enables you to create lists just as the ComboBox does, but the list menu is always visible (see Figure 33-11). If there are more items than the height of the instance allows, a scroll bar is automatically added to the list. This component enables selection of one or more items. As with the ComboBox component, keyboard navigation is allowed, and a zero-based index system is used for the arrays populating the label and data parameters.

Figure 33-11: The List component at run time

Parameters

The List component parameters include an additional option to select multiple values. Other settings in this tab are similar in function to components we mentioned earlier.

How it Works

This component's functionality is very similar to that of the ComboBox component. The main difference in a List component is the visibility of the labels and the ability to select multiple values. If you wish to add functionality using ActionScript, the methods, property, and events of the List class are used.

Tip 

If you're using Flash Professional 8, you should know that many components inherit the List class, such as the DataGrid and the ComboBox components. Any component that is based on the List class can also use a custom cell renderer class, which determines how the content of each row in a List instance is laid out and formatted.

RadioButton Component

The RadioButton component looks and feels similar to those found in HTML forms. Based on the design of radio button functionality, only one radio button can be selected within a group of buttons. Figure 33-12 shows a group of RadioButton instances in a Flash movie.

Figure 33-12: A group of RadioButton instances

Parameters

The RadioButton component has the unique attribute for setting a Group name, which will associate the instance with others on the Stage. Other parameters resemble those of components we discussed earlier.

How it Works

The groupName parameter is important to understand. Groups of buttons can be added to your document, and in each group, only one button can be selected at a time. You can resize the width and height of an instance with the Free Transform tool, the Property inspector, or the Transform panel to accommodate your label alignment parameter. The hit area of the RadioButton instance surrounds both the button and the label area. Added functionality can be controlled using the RadioButton class's methods, properties, and events in ActionScript.

Note 

It is important to consider the interactive design of your movie when you add radio buttons or check boxes to your movies. Your decision should not be based on the "look" of a radio button versus a check box. Radio buttons should only be used when you need one selection to be made from several choices, and a radio button should never exist outside of a group (that is, you shouldn't have a single radio button appearing on its own). Check boxes should be used when you need to allow one or more selections to be made from several choices. You can also use a check box for a single option (for example, a form may have a check box asking if you want to receive promotional e-mails for a product). We recommend that you carefully consider how these elements are designed for use in applications, because this enhances the usability of your production.

ScrollPane Component

The ScrollPane component is potentially a very powerful and diverse tool. It adds a window with vertical and horizontal scroll bars on either side and is used to display linked Movie Clip symbols from the Library on to the Stage. Because the component features scroll bars, you are able to accommodate more content within a smaller footprint on the Stage. Figure 33-13 shows a ScrollPane instance displaying a linked Movie Clip symbol.

Figure 33-13: The ScrollPane component at run time

Parameters

Parameters for the ScrollPane component will link it to a Movie Clip symbol and also control how your end-user will be able to manipulate the ScrollPane content. You can also control scroll bar positioning and visibility with these parameters:

How it Works

The ScrollPane component can display Movie Clips (or bitmap images) with linkage IDs, so you will need to convert any other symbol types or bitmap images to Movie Clips for the images to display. You can also specify external content as a URL in the contentPath property. The Movie Clip (or bitmap image) simply has to be in the Library and have the Export for ActionScript setting checked in the Linkage Properties dialog box.

TextArea Component

The TextArea component, shown in Figure 33-14, can be thought of as a ScrollPane component for text. The purpose of the TextArea component is to display text or HTML formatted text within a display window, complete with vertical and/or horizontal scroll bars.

Figure 33-14: The TextArea component displaying HTML formatted text

Parameters

The settings for the TextArea component in the Property inspector control the text that is displayed in the instance.

Note 

Horizontal scroll bars will be added only to TextArea instances if wordWrap is set to false and the text width for a line extends beyond the visible display area.

How it Works

The TextArea component takes the text parameter value and displays it within the visible area of the instance. The TextArea component can be further enhanced or controlled with ActionScript, by utilizing the methods, properties, and event handlers of the TextArea class.

Cross-Reference 

You can see the TextArea component in Chapter 20, "Making Your First Flash 8 Project."

UIScrollBar Component

The UIScrollBar component, shown in Figure 33-15, was added to the Flash MX 2004 7.2 Updater, and continues to be available in the new release of Flash 8. With the UIScrollBar component, you can scroll your own TextField instances, and you can scroll other MovieClip-based content. The UIScrollBar component can snap to objects on the Stage, and auto-resize its height to match the height of the snapped-to TextField instance.

Figure 33-15: The UIScrollBar component beside a TextField instance

Cross-Reference 

Read our coverage of the new scrollRect property of the MovieClip class in Chapter 30, "Applying HTML and Text Field Formatting," to learn more about using the UIScrollBar component to scroll MovieClip object content.

Parameters

The settings for the UIScrollBar component in the Property inspector control the target to which the scroll bar is linked and whether the scroll bar is scrolling horizontal content or vertical content.

Figure 33-16: A UIScrollBar instance with a horizontal value of true

How it Works

When you set the _targetInstanceName property to the name of a TextField instance, the UIScrollBar component controls the scroll property of that TextField instance. It can determine the range of the scroll bar movement by looking at the TextField instance's maxscroll property.

Cross-Reference 

To learn more about the scroll and maxscroll properties of the TextField class, read Chapter 30, "Applying HTML and Text Field Formatting."

Note 

Both Flash Basic 8 and Flash Pro 8 also include other UI components, including the Label, Loader, NumericStepper, ProgressBar, and Window components. We discuss the Loader and ProgressBar components in Chapter 28, "Sharing and Loading Assets," and an example of the NumericStepper component is available in the CD-ROM files for Chapter 30, "Applying HTML and Text Field Formatting."

Категории