• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Populating Components

1.
First, let’s populate a ComboBox component. (We can skin it later.) From the Components panel, drag an instance of the ComboBox component onto the Stage. From the Parameters tab in the Properties panel, click to enter values into the Labels parameter. Click the plus button and enter three values—such as “Macromedia,”“Microsoft,” and “New Riders” (see Figure W7.1).

Figure W7.1. Parameters that contain multiple values are populated through this dialog box.


2.
Next, populate the Data parameter with three URLs to match the three items entered as labels (for example, http://www.macromedia.com, http://www.microsoft.com, and http://www.newriders.com).

3.
Finally, specify the Change Handler to read jumpTime. We’ll have to also write this function. (Some programming tools use the term “handler” to mean “function.”) Anyway, in the first frame of the main timeline, type this jumpTime() function:

function jumpTime(who){
  trace(who.getValue()); 
}

If you test the movie, you’ll see the URL any time an item is selected from the ComboBox component. Even though we didn’t specify a parameter for the jumpTime() function, this component automatically passes a reference to the component that triggers the function. That’s nice in this case because we won’t have to name the instance. If you had several ComboBox instances on the Stage, you’d probably want to know which one triggered the function (instead of, perhaps, making a different function for each one). Anyway, I found the getValue() method under FlashUIComponents, FComboBox in the Actions panel. It returns the currently selected value (not just item number).

Obviously, you could change the trace statement to do a getURL (for example, getURL(who.getValue())). Before you do that, I’ll just show a solution to making this ComboBox component trigger only when the user changes the selected item.

4.
To modify the way the ComboBox component works, we won’t really change the component but rather how our function responds to it. Check out this finished version of the jumpTime() function:

function jumpTime(who){
  if (lastTime==who.getSelectedIndex()){
    return; 
  } 
  lastTime=who.getSelectedIndex(); 
  getURL(who.getValue()) 
}

Now you can’t navigate to the same place twice in a row. For example, if the user makes a selection, and then selects the menu and decides not to change anything, it won’t take them anywhere (the way it did before). The code stores the last selected item number in the lastTime variable. Then, every time this function is triggered, we first check to see whether the current selected index (using another ComboBox method, getSelectedIndex()) is the same; if it is, we return and skip the rest of the code. This is just one solution. We’ll come back to this ComboBox component to add a new skin. Now let’s go and tweak the code in some of the other components.

To follow the next section, you need to download and install the Extension Manager and the Flash UI Components Set 2. You can find them both at www.macromedia.com/exchange/flash.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint