The following example shows how you can set a custom text format on a Flash ActionScript 3.0 TextInput component by setting the textFormat style to a TextFormat object.

Full code after the jump.

// ActionScript 3.0
/* Requires:
 * - TextInput component in Flash library
 */
import fl.controls.TextInput;
 
var textFmt:TextFormat = new TextFormat();
textFmt.color = 0xFF0000;
textFmt.font = "Courier New"
textFmt.size = 18;
 
var textInput:TextInput = new TextInput();
textInput.text = new Date().toString();
textInput.setStyle("textFormat", textFmt);
textInput.width = 300;
textInput.move(10, 10);
addChild(textInput);
Tagged with:
 

3 Responses to Setting a custom text format on a TextInput control in Flash using ActionScript 3.0

  1. Aaron says:

    Can one vertically align text within a textinput field to the middle or the vertical center of the box? I have a textinput that I resized the height but the text stays in the upper left corner, which is pretty ugly. Any help you can give is very much appreciated.

  2. Gabe E. says:

    Awesome :D! Just what I was looking for :)! Thanks for sharing, Peter :)!
    This website is so useful :D! I love your posts!

  3. Gabberwocky says:

    Ok, if I want to get my text formatted a certian way but I already have a bunch of different text boxes with different text on different keyframes, how do I copy the style of the text in one box and apply it to the next so I don’t have to keep changing the color on each text box. Is there a way to copy just the attributes of a text box?

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree