ComboBox changes Font Size

Flashers,

Question (overall)
How do I use a comboBox to change Font Size of a textfield?

What’s Working
I have all the sizes loaded into the comboBox - when clicked it displays all the possible font sizes (ie. 4 - 40 for my uses). The thing is when I click it it doesn’t do anything.

I really don’t know where to start getting this to work. I did the easy part. I know there are text Editors (and even better ones that cost), but I’m wanting to 1) know what I’m doing and 2) have it just change the font size.

Current Settings
Publishing with AS 2.0 and using the ComboBox Component that comes with MX2004 (F7)

**Script
**


sizeListChange = new Object();
sizeList.addEventListener("change", sizeListChange);
myTextFormat = new TextFormat();
sizeList.addItem("6", 6);
sizeList.addItem("8", 8);
sizeList.addItem("9", 9);
sizeList.addItem("10", 10);
sizeList.addItem("11", 11);
sizeList.addItem("12", 12);
sizeList.addItem("14", 14);
sizeList.addItem("16", 16);
sizeList.addItem("20", 20);
sizeList.addItem("24", 24);
sizeList.addItem("36", 36);
sizeList.addItem("40", 40);
sizeListChange.change = function(evt, myTextFormat){
    myTextFormat = currentFormat;
    myTextFormat.size = evt.target.selectedItem.label;
    myTextFormat.textHeight = evt.target.selectedItem.label;
    textIns_txt.setTextFormat(begin, end, myTextFormat);
}

ANSWERS

**
I learned / Mistakes I’ve noticed
**[LIST]
[]The sizeListChange object must be created FIRST - I moved the creation to the beginning of the code.
[
]myTextFormat.textHeight needs to use/equal the ComboBox’s selectedItem’s data.
[*]There is probably a better way to say this: When the change is initiated a variable is going to be used and is defined in the function’s brakets (eg see below)

function(evt)

. Then the evt must be followed by target. Now you can use any of the comboBox Class lines.[/LIST][INDENT][INDENT][INDENT]Macromedia/Adobe puts it this way “You define a method with the same name as the event on the listener object; the method is called when the event is triggered. When the event is triggered, it automatically passes an event object (eventObject) to the listener object method. Each event object has a set of properties that contains information about the event. You can use these properties to write code that handles the event.”[/INDENT][/INDENT][/INDENT]

Correct Script


myTextFormat = new TextFormat();
myTextFormat.bold = false;
myTextFormat.italic = false;
myTextFormat.underline = false;

sizeList.addItem("6", 6);
sizeList.addItem("8", 8);
sizeList.addItem("9", 9);
sizeList.addItem("10", 10);
sizeList.addItem("11", 11);
sizeList.addItem("12", 12);
sizeList.addItem("14", 14);
sizeList.addItem("16", 16);
sizeList.addItem("20", 20);
sizeList.addItem("24", 24);
sizeList.addItem("36", 36);
sizeList.addItem("48", 48);
sizeList.addItem("56", 56);
sizeList.addItem("72", 72);
sizeList.setSize(40);
sizeListChange = new Object();
sizeList.addEventListener("change", sizeListChange);
sizeListChange.change = function(evt){
    myTextFormat = currentFormat;
    myTextFormat.size = evt.target.selectedItem.label;
    myTextFormat.textHeight = evt.target.selectedItem.data;
    textIns_txt.setTextFormat(begin, end, myTextFormat);
};