Flash Script – Listbox Component

Share this article

How can you use the listbox component? Here’s a quick tour!

1. Open the components panel — hit ctrl+f7.

2. Drag the Listbox component onto the stage, and select the Listbox component in Frame 1. The component’s parameters are displayed in the Property inspector.

3. Name the component. Type "listbox" in the Property inspector Instance Name text box.

4. The Labels parameter displays a list of values users can select. Click the Labels field, then click the magnifying glass to open the Values pop-up window. Click the Plus (+) button to enter a new value.

1184_1

5. Click in the default value field, then type "one" for the first value. Click the Plus (+) button to enter the next value. Click in the default value field and type "two" for the next value.

Repeat this process to add the values for "three", "four", "five", and "six". When you’re finished, click Ok to close the label box.

6. The Data parameter is optional. It’s used to specify the values associated with the items (or labels) in the list box. There is no need to associate values with our labels in this case, so we won’t bother with this parameter.

7. The Select Multiple parameter specifies multiple selection. Set this to true, top allow users to select more than one option fromt eh list at a time.

8. Name the Click Handler. Type "f1" for the Click Handler name.

1184_2

9. Now, create two dynamic text fields as shown above. Give the first text field a variable name of "txt1", and call the second "txt2".

10. Select the first key frame from the existing layer, and press f9 to open the actions box. Insert the following code:

function f1() 
{
//to get the item label
txt1.text = listbox.getSelectedItem().label;
//to get the multiple item values
txt2.text = listbox.getSelectedIndices();
}

Finished! Test the movie.

Georgina LaidlawGeorgina Laidlaw
View Author

Georgina has more than fifteen years' experience writing and editing for web, print and voice. With a background in marketing and a passion for words, the time Georgina spent with companies like Sausage Software and sitepoint.com cemented her lasting interest in the media, persuasion, and communications culture.

Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week