# ComboBox changes Font Size

**URL:** <https://forum.kirupa.com/t/combobox-changes-font-size/197848>\
**Category:** flash\
**Created:** [August 19, 2006, 9:33pm UTC](https://forum.kirupa.com/t/combobox-changes-font-size/197848 "2006-08-19T21:33:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbailey](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jbailey/32/2380_2.png) [@jbailey](https://forum.kirupa.com/u/jbailey)\
**Post date:** [August 19, 2006, 9:33pm UTC](https://forum.kirupa.com/t/combobox-changes-font-size/197848/1 "2006-08-19T21:33:10Z")

</div>

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  
\*\*

```auto

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)

```auto
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**

```auto

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);
};

```
