31 July 2011 ~ 0 Comments

AS3 Add TextField with Format

// here are your imports

import flash.text.TextFormat;

import flash.text.AntiAliasType;

import flash.text.*;

// here is your text format - Verdana would need to be embedded via AS3 or in the Flash IDE

var format:TextFormat = new TextFormat();

format1.font="Verdana";

format1.size=18;

format1.bold = true;

format1.color = 0x000000;

format1.letterSpacing=2;

// I usually center my textFields.

format1.align = TextFormatAlign.CENTER;

// here are your variables

var stringWidth = 100;

var stringX = 0;

var stringY = 0;

var string = "here is your string"

// here is your actual textField

var string_txt = new TextField();

addChild(string_txt);

string_txt.width=stringWidth;

string_txt.x=stringX;

string_txt.y=stringY;

string_txt.embedFonts = true;

string_txt.wordWrap = true;

string_txt.autoSize="left";

string_txt.defaultTextFormat = format1;

string_txt.htmlText = string;

via [ActionScript 3] AS3 Add TextField with Format – Pastebin.com.

Leave a Reply


3 + = five