Creating an application with the List component

The following procedure explains how to add a List component to an application while authoring. In this example, the list is a sample with three items.

To add a simple List component to an application:

  1. Select File > New and choose Flash File (ActionScript 2.0).
  2. Drag a List component from the Components panel to the Stage.
  3. Select the Free Transform tool and resize the component to fit your application.
  4. In the Property inspector, do the following:
  5. Select Control > Test Movie to see the list with its items.
  6. Return to the authoring environment, insert a new layer, and name it actions.
  7. Add the following ActionScript to Frame 1 of the actions layer.
    my_list.change = function(evt:Object) {
        getURL(evt.target.selectedItem.data, "_blank");
    };
    my_list.addEventListener("change", my_list);
    

To populate a List instance with a data provider:

  1. Select File > New and choose Flash File (ActionScript 2.0).
  2. Drag a List component from the Components panel to the Stage.
  3. Select the Free Transform tool and resize the component to fit your application.
  4. In the Property inspector, enter the instance name my_list.
  5. Select Frame 1 of the Timeline and, in the Actions panel, enter the following:
    my_list.dataProvider = myDP;
    

    If you have defined a data provider named myDP, the list fills with data. (For more information about data providers, see List.dataProvider.)

  6. Select Control > Test Movie to see the list with its items.

To use a List component to control a movie clip instance

  1. Select File > New and choose Flash File (ActionScript 2.0).
  2. Drag a List component from the Components panel to the Stage.
  3. Select the Free Transform tool and resize the component to fit your application.
  4. In the Property inspector, enter the instance name my_list.
  5. Create a movie clip on the Stage and give it the instance name my_mc.
  6. Open the movie clip in symbol-editing mode and add some animation.
  7. Insert a new layer and name it actions.
  8. Add the following ActionScript to Frame 1 of the actions layer.
    my_list.addItem({label:"play", data:"play"});
    my_list.addItem({label:"stop", data:"stop"});
    var listHandler:Object = new Object();
    listHandler.change = function(evt:Object) {
        switch (evt.target.selectedItem.data) {
        case "play" :
            my_mc.play();
            break;
        case "stop" :
            my_mc.stop();
            break;
        default :
            trace("unhandled event: "+evt.target.selectedItem.data);
            break;
        }
    };
    my_list.addEventListener("change", listHandler);
    
  9. Select Control > Test Movie to use the list to stop and play the my_mc movie clip instance.

To create a List component instance using ActionScript:

  1. Select File > New and choose Flash File (ActionScript 2.0).
  2. Drag the List component from the Components panel to the library.

    This adds the component to the library, but doesn't make it visible in the application.

  3. Select the first frame in the main Timeline, open the Actions panel, and enter the following code:
    this.createClassObject(mx.controls.List, "my_list", 1);
    my_list.addItem({label:"One", data:dt1});
    my_list.addItem({label:"Two", data:dt2});
    

    This script uses the method UIObject.createClassObject() to create the List instance.

  4. Select Control > Test Movie.

Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00003161.html