Skip to main content
Participant
August 9, 2011
Answered

Styling a dynamic text field

  • August 9, 2011
  • 1 reply
  • 490 views

Hi guys

I am having a problem styling a dynamic text (see code below) as the font and font size are not working on our movie.

Can you spot, what we could be doing wrong?

Thanks in advance
Andres


     
var count:Number = 10082145;
var maxNum:Number = 20082145;
var num:Number = 1;
this.createTextField("txt", this.getNextHighestDepth(), 900, 20, 100, 50) ;
txt.textColor = 0xFFFFFF;
var emphatic:TextFormat = new TextFormat();
emphatic.bold = true;
emphatic.size = 16;
emphatic.font = "Arial";
txt.setTextFormat(emphatic);

onEnterFrame = function () {
    count += num;
    if (count >= maxNum) {
        num = 0;
        txt.text = "20082145";
    } else {
        var v = count / (maxNum / 20082145);
        txt.text = v;
       
        var str = String(v);
        var io = str.indexOf('.');
        if (io == -1)
        {
            txt.text = v + '0';
        }
    }


   
};

This topic has been closed for replies.
Correct answer Ned Murphy

Try using:  txt.setNewTextFormat(emphatic);

I believe setTextFormat needs to be applied after text is written into the textfield, not before.  But setNewTextFormat is supposed to assign the default format for the textfield ahead of text being assigned.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
August 9, 2011

Try using:  txt.setNewTextFormat(emphatic);

I believe setTextFormat needs to be applied after text is written into the textfield, not before.  But setNewTextFormat is supposed to assign the default format for the textfield ahead of text being assigned.

Participant
August 9, 2011

Thanks, it works as expected...

Ned Murphy
Legend
August 9, 2011

You're welcome