PDA

View Full Version : Dropdown Change Handlers


ninjapheret
08-20-2004, 04:34 PM
I'm having some difficulties getting my Change Handler to work on a dropdown list.

Here's the .fla:

donors.fla (http://www.petrafineart.com/presentation/donors.fla)

I have a textbox on the left side of the stage, it is dynamic, and the instance is named "inscription." I have a dropdown in the middle (nameBox), with values and data, and a piece of code in its 'change handler' as follows:

inscription.htmlText = nameBox.getSelectedItem().data;

I cannot get the inscription box to display any text! What am I doing wrong here? I've tried placing the above line into the AS of the inscription box, but then I only get the data displayed of the first item in the dropdown - if i change items the text remains the same.

Can anyone help me with this?

ninjapheret
08-20-2004, 06:22 PM
bringing this up top....anyway i can get some tips?

tdoublea
08-22-2004, 05:40 AM
hi ninjapheret.



inscription.html = true;

nameBox.addItem({label:"theName", data:"myData"});

nameBox.addEventListener("change", this);

function change(eventObject:Object){
var selectedCB:Object = eventObject.target;
var selectedData = selectedCB.selectedItem.data;

inscription.htmlText = selectedData;
}



hope that helps

ninjapheret
08-23-2004, 06:11 PM
tdoublea -

Do I apply this to Frame 1? I'm not getting any results with it... sorry, but do you know what my problem is? and WHY wouldn't the line on change handler

inscription.htmlText = nameBox.getSelectedItem().data;

not do anything? i mean wtf? ;)

any help from anyone would be appreciatd.

tdoublea
08-23-2004, 07:45 PM
hey ninjapheret.

I don't think there is a method calles getSelectedItem()

there is getItemAt('the number')
or selectedItem

if you wanted to grab info from an item in the comboBox, you would use getItemAt()

-ie
var theItemNum = comboBox.selectedIndex;
var theData = comboBox.getItemAt(theItemNum).data;

and selectedItem is the item selected from the comboBox

-ie

var theData = comboBox.selectedItem.data;

I would set all the text formatting and the change function on frame one
and then set the changeHandler for the comboBox when ever you attach it of it appears on the stage, and the textFormat for the textbox whereever that shows up

frame 1:

var myTF = new TextFormat();
myTF.font = "_sans";
myTF.embedFonts = true;
myTF.html = true;
...etc

function change(eventObject:Object){
var selectedCB:Object = eventObject.target;
var selectedData = selectedCB.selectedItem.data;
trace(selectedData);
inscription.htmlText = selectedData;
}

whereever the textbox 'inscription' appears (make sure inscription is the Instance Name and not the Variable Name in the properties panel):

inscription.setNewTextFormat(myTF);
inscription.setTextFormat(myTF);

whereever the comboBox makes its appearance:

nameBox.addItem({label:"theName", data:"myData"});
nameBox.addEventListener("change", this);

////
re: inscription.htmlText = nameBox.getSelectedItem().data;

i would stay away from using functions within the assigning of variables