Flash CS3 Documentation |
|||
| Using ActionScript 3.0 Components > About ActionScript 3.0 Components > Adding to and deleting from a document | |||
When you drag a FLA-based component from the Components panel to the Stage, Flash imports an editable movie clip to the library. When you drag a SWC-based component to the Stage, Flash imports a compiled clip to the library. After a component has been imported to the library, you can drag instances of it to the Stage from either the Library panel or the Components panel.
You can add a component to a document by dragging it from the Components panel. You can set properties for each instance of a component in the Parameters tab of the Property inspector or in the Parameters tab in the Component inspector.
The following illustration shows the Property inspector for a Button component.
Component settings in the Property inspector
For more information, see "Setting parameters and properties" on page 888.
For more information on sizing specific component types, see Chapter 4, "Customizing the UI Components," on page 989.
You can also change the color and text formatting of a component by setting style properties for it or customize its appearance by editing the component's skins. For more information on these topics, see Chapter 4, "Customizing the UI Components," on page 989.
If you drag a component to the Stage during authoring, you can refer to the component by using its instance name (for example, myButton).
To add a component to a document at run time with ActionScript, the component must first be in the application's library (Window > Library) when the SWF file is compiled. To add a component to the library, drag the component from the Components panel into the Library panel. For more information on the library, see "The library" on page 891.
You must also import the component's class file to make its API available to your application. Component class files are installed in packages that contain one or more classes. To import a component class, use the import statement and specify the package name and class name. You would import the Button class, for example, with the following import statement:
import fl.controls.Button;
For information on what package a component is in, see the ActionScript 3.0 Language and Components Reference. For information about the location of component source files, see "Working with component files" on page 884.
To create an instance of the component, you must invoke the component's ActionScript constructor method. For example, the following statement creates an instance of a Button called aButton:
var aButton:Button = new Button();
The final step is to call the static addChild() method to add the component instance to the Stage or application container. For example, the following statement adds the aButton instance:
addChild(aButton);
At this point, you can use the component's API to dynamically specify the component's size and position on the Stage, listen for events, and set properties to modify its behavior. For more information on the API for a particular component, see the ActionScript 3.0 Language and Components Reference.
For more information on the addChild() method, see "Working with the display list" on page 896.
Flash CS3