Components

In the next example, instead of setting the data bindings for the combo box in the Component Inspector, we set them using ActionScript. This movie displays a list of websites and links to them when one is clicked.

  1. Start a new ActionScript3 movie and save it as links.fla.
  2. From the menu select Window, Components. In the components window drag a ComboBox component to the stage.
  3. Open the property window and name the ComboBox cboLinks.
The array websites is enclosed inside a pair of brackets: []. Each item in the array consists of a label and data inside braces: {} Check your format carefully!
Get Adobe Flash player
The code is shown below:
import fl.controls.List; 
import fl.data.DataProvider; 

var websites: Array = [
    {label:"Yahoo", data:"http://www.yahoo.com"},
    {label:"Google", data:"http://www.google.com"},
    {label:"Hello-World", data:"http://www.hello-world.com"},
	{label:"Zebra0", data:"http://www.zebra0.com"}
  ]; //list of websites and link
cboLinks.dataProvider = new DataProvider(websites);
cboLinks.addEventListener(Event.CHANGE, linktoPage);

function linktoPage(event:Event):void {
   var site: URLRequest = new URLRequest();
   site.url = cboLinks.selectedItem.data; //Retrieves data part from array
   navigateToURL(site); //Flash function to navigate to a webpage
} //linktoPage
Download the movie

NEXT: Radio Buttons