My TextFormat won’t stick to my TextField

Posted on

Run this SWF and click the button, the text stays pink.
Then run this and click on the text, then click the button.
The text defaults size and color. Why??????textFormatBug

var titleTF:TextFormat = new TextFormat();
titleTF.color = 0xFF00FF;
titleTF.size = 22;
//titleTF.font = avantBold.fontName;
var titleText:TextField = createTF(10, 10, 200, 26, true, titleTF, “This is a test”);

function createTF(_x:Number, _y:Number, _width:Number, _height:Number, _autoSize:Boolean, _defaultTF:TextFormat, _text:String):TextField {
var tf:TextField = new TextField();
tf.x = _x;
tf.y = _y;
tf.width = _width;
tf.height = _height;
tf.autoSize = (_autoSize) ? TextFieldAutoSize.LEFT : TextFieldAutoSize.NONE;
tf.wordWrap = true;
tf.multiline = true;
tf.defaultTextFormat = _defaultTF;
tf.htmlText = _text;
return tf;

clicker.addEventListener(MouseEvent.CLICK, swapText);

function swapText(e:*):void{
titleText.htmlText = “This is now a changed test” + String(Math.random());;

One thought on “My TextFormat won’t stick to my TextField

  1. This is because of htmlText for the defaultTextFormat . If you use just text with defaultTextFormat it will work. It’s because htmlText has markup tags that override defaultTextFormat.

    Thats also true for setTextFormat, but setTextFormat also has a problem with the getting overrided by just text too because it’s ment to have a start and end index.

    It’s Best practice to apply the TextFormat again after you change the text.
    This will guaranty that it’s always the right TextFormat.

Leave a Reply

Your email address will not be published. Required fields are marked *