Flash Script – Listbox Component

By Georgina Laidlaw

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.


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.


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.

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

No Reader comments

Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in Front-end, once a week, for free.