DekGenius.com
[ Team LiB ] Previous Section Next Section

Recipe 11.1 Adding UI Components at Runtime

11.1.1 Problem

You want to add UI components such as combo boxes, list boxes, and push buttons to a movie at runtime.

11.1.2 Solution

Add the component to the Library at authoring time and use attachMovie( ) to create a runtime instance.

11.1.3 Discussion

You can use attachMovie( ) to add UI components to your movies at runtime, just as you would any other movie clip. However, you must first add the components to the movie's Library. To do so, you must drag a component from the Components panel to the Stage during authoring, which also places a copy of the component in your Library under the heading "Flash UI Components." Flash automatically copies over any subcomponents that are needed; for example, dragging a list box to the Stage copies both the ListBox component and the ScrollBar component, on which list boxes rely, to the Library.

You can optionally delete the component instances from the Stage, but the components remain accessible in the Library. The component symbols are automatically set for export, and you should leave the linkage identifier names at their defaults, as listed in Table 11-1.

Table 11-1. UI component linkage identifiers

Component

Linkage identifier

List box

FListBoxSymbol

Combo box

FComboBoxSymbol

Checkbox

FCheckBoxSymbol

Radio button

FRadioButtonSymbol

Push button

FPushButtonSymbol

Scrollbar

FScrollBarSymbol

Scroll pane

FScrollPaneSymbol

Message box

FMessageBoxSymbol

Once a component symbol is within a movie's Library, the procedure for adding instances at runtime with attachMovie( ) is exactly the same as with any other movie clip. For example, this code creates a new movie clip instance of the CheckBox UI component and names it myCheckBox_ch:

_root.attachMovie("FCheckBoxSymbol", "myCheckBox_ch", 1);

11.1.4 See Also

Recipe 7.1, Recipe 7.19, Recipe 11.3, Recipe 11.7, Recipe 11.10, and Recipe 11.15

    [ Team LiB ] Previous Section Next Section