# Random change font of text box

**URL:** <https://forum.kirupa.com/t/random-change-font-of-text-box/206357>\
**Category:** flash\
**Created:** [November 7, 2006, 2:31pm UTC](https://forum.kirupa.com/t/random-change-font-of-text-box/206357 "2006-11-07T14:31:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![coop](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@coop](https://forum.kirupa.com/u/coop)\
**Post date:** [November 7, 2006, 2:31pm UTC](https://forum.kirupa.com/t/random-change-font-of-text-box/206357/1 "2006-11-07T14:31:54Z")

</div>

Hi all,

I have code for a typewriter type effect where the text is added one letter at a time, this is fine but I wanted the font used to be random from a list of fonts.  
The fonts in font\_arr i have placed in the library with NEW FONT, and in the linkage exported for actionscript.

[AS]  
font\_arr = [“Baskerville”, “AppleGothic”, “American Typewriter”];  
startRan = Math.floor(Math.random()\*font\_arr.length);  
changeFont(font\_arr[startRan], textBox\_txt);  
trace(font\_arr[startRan]);  
this.onLoad = function() {  
typeInterval = setInterval(typeset, 50);  
};  
k = 0;  
typeset = function () {  
text = “testing testing testing testing”;  
if (k\<text.length) {  
textBox\_txt.text = text.substring(0, k);  
k++;  
} else {  
textBox\_txt.text = text;  
clearInterval(typeInterval);  
}  
};  
changeFont = function (fontface, where) {  
myFont = new TextFormat();  
myFont.font = fontface;  
where.setTextFormat(myFont);  
};  
[/AS]
