PDA

View Full Version : Flash UIComponent question


Proxicide
06-07-2005, 08:52 AM
Hello.

I want to set up a list box (or combo box), that will automatically trigger an action once the user clicks on an item within that box. I don't want the user to have to click to select an item, then have to click another button to trigger the action, but rather, have the action triggered right at the moment when the user selects the item.

I tried making the component a movie clip, and placing an "on (release) {}" event handler for the clip, but that just hides the functionality of the component, and the user wouldn't be able to select anything.

Thanks.

BTW, I'm using Flash MX (not MX 2004). If that really matters.

tobyw_1969
06-07-2005, 01:00 PM
You can use the built-in event functionality of the comboBox component. There are actually two ways.

The first is to place some code directly onto the component, like this:

on(change){
trace("you selected : " + this.selectedItem.label);
}

However, since placing code directly onto objects is very bad practice, it is better to use the other way, but unfortunately Macromedia have created a ridiculously tortured and convoluted event listener model for doing this, but here goes anyway:

Call your comboBox 'cBox' and then put this code in your main timeline

listenerObj = new Object();
listenerObj.change = function(){
trace ("you selected:" + _root.cBox.selectedItem.label);
}
cBox.addEventListener("change",listenerObj);


Sadly they haven't thought of making a dynamic callback function like 'onChange' which can be defined like 'onRelease' can for a movieClip, so you always have to use the create object/add listener method. Oh well.