Monday, 2 July 2012

AS3 Change dynamic text colour

I was trying to figure out how to change the dynamic text colour using Actionscript 3 code. After looking up the TextFormat class I came up with the following solution. In the code below I have a dynamic text field on the stage with the instance name: txt and I want to change the colour to blue.

txt.text = 'Hello ilike2flash';

var textformat:TextFormat = new TextFormat();
textformat.color = 0x0000ff;
txt.setTextFormat(textformat);

The process is the same for text fields generated using purely Actionscript 3 code.
 var textformat:TextFormat = new TextFormat();
textformat.color = 0x0000ff;
textformat.size = 20;
textformat.font = new Font1().fontName;

var tf:TextField = new TextField();
tf.embedFonts = true;
tf.defaultTextFormat = textformat;
tf.text = 'Hello ilike2flash';
tf.width = tf.textWidth + 5;
addChild(tf);

0 comments:

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP