# \[FMX\] dynamically resize fonts

**URL:** https://forum.kirupa.com/t/fmx-dynamically-resize-fonts/19973
**Category:** flash
**Created:** [May 3, 2003, 2:36pm UTC](https://forum.kirupa.com/t/fmx-dynamically-resize-fonts/19973 "2003-05-03T14:36:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tgelston](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/tgelston/32/54_2.png) [@tgelston](https://forum.kirupa.com/u/tgelston)
#### Post date: [May 3, 2003, 2:36pm UTC](https://forum.kirupa.com/t/fmx-dynamically-resize-fonts/19973/1 "2003-05-03T14:36:31Z")

</div>

Hi all!

I have a dynamic text box of fixed with - lets say 200px wide.  
This box will display a user input line - I want the font in the box to dynamically resize so it will fit nicely- if the user types “Cat” the text will be very large (it doesnt have to fit perfect) and if they type “The cat in the hat was a very fine book” the font size would decrease so it will still fit in that 200 px width.

I have found this “TextField.setTextFormat” in the AS dict. but don’t really understand how to pass anything along.

If this is to difficult I will accept making the text multiline - something I also can’t seem to figure out.

Thanks,  
Tobias

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 3, 2003, 3:54pm UTC](https://forum.kirupa.com/t/fmx-dynamically-resize-fonts/19973/2 "2003-05-03T15:54:46Z")

</div>

I’m not very advanced in actionscript but this seemed like a nice assignment for myself. It sort of works but there remain 2 problems:

- the transistions from fontsize are kind of jagged in the beginning
- it doesnt allways keep the the text in the box and if that happens the first letters will scroll of the screen  
If anyone would be able to contribute solving these problems im sure tgelston and I would be very gratefull.

Anyway here is my setup, hope it helps you out a bit:

```auto

format = new TextFormat();
this.createTextField("blaat", 1, 10, 10, 200, 400);
format.size = 20;
blaat.border = true;
blaat.type = "input";
blaat.onChanged = function() {
	if (blaat.textWidth == 0) {
		format.size = 20;
	} else {
		ratio = blaat._width/blaat.textWidth;
		format.size *= ratio;
		blaat.setTextFormat(format);
	}
};

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 5, 2003, 10:54am UTC](https://forum.kirupa.com/t/fmx-dynamically-resize-fonts/19973/3 "2003-05-05T10:54:49Z")

</div>

Great - Thank you!

–Tobias

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 6, 2003, 7:27am UTC](https://forum.kirupa.com/t/fmx-dynamically-resize-fonts/19973/4 "2003-05-06T07:27:46Z")

</div>

no problem, but like i said it could work a bit prettier, maybe if you limit the fontsize? the big fonts have rather big intervals
