Adding components using ActionScript

To add a component to a document using ActionScript, you must first add it to the library.

You can use ActionScript methods to set additional parameters for dynamically added components. For more information, see Components Dictionary.

Note: The instructions in this section assume an intermediate or advanced knowledge of ActionScript.

To add a component to your Flash document using ActionScript:

  1. Drag a component from the Components panel to the Stage and delete it.

    This adds the component to the library.

  2. Select the frame in the Timeline where you want to place the component.
  3. Open the Actions panel if it isn't already open.
  4. Call the createClassObject() method to create the component instance at runtime.

    This method can be called on its own, or from any component instance. It takes a component class name, an instance name for the new instance, a depth, and an optional initialization object as its parameters. You can specify the class package in the className parameter, as in the following:

    createClassObject(mx.controls.CheckBox, "cb", 5, {label:"Check Me"}); 
    

    Or you can import the class package, as in the following:

    import mx.controls.CheckBox;
    createClassObject(CheckBox, "cb", 5, {label:"Check Me"}); 
    

    For more information, see UIObject.createClassObject().

  5. Use the ActionScript methods and properties of the component to specify additional options or override parameters set during authoring.

    For detailed information on the ActionScript methods and properties available to each component, see their entries in Components Dictionary.