Posted By

chrisaiv on 12/03/08


Tagged

font label as3


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

sillicon
THEPWN3R
vip4lyf
tspitzr


As3: Adding a font to a Label component (fl.controls.Label)


 / Published in: ActionScript 3
 

URL: http://www.adobe.com/devnet/flash/quickstart/label_component_as3/#section7

I borrowed this example from the link above

  1. // Import the required component classes.
  2. import fl.controls.Label;
  3.  
  4. // Create a new instance of the Font1 symbol from the document's library.
  5. var myFont:Font = new MyFont();
  6.  
  7. // Create a new TextFormat object, and set the font and size properties.
  8. var myTextFormat:TextFormat = new TextFormat();
  9. myTextFormat.font = myFont.fontName;
  10. myTextFormat.size = 8;
  11.  
  12. /* Create a new Label component instance, set the textField.antiAliasType property,
  13.   set the embedFonts and textFormat styles, and add the label to the display list. */
  14. var myLabel:Label = new Label();
  15. myLabel.text = "The quick brown fox jumped over the lazy dog";
  16. myLabel.autoSize = TextFieldAutoSize.LEFT;
  17. myLabel.move(10, 10);
  18. myLabel.textField.antiAliasType = AntiAliasType.ADVANCED;
  19. myLabel.setStyle("embedFonts", true);
  20. myLabel.setStyle("textFormat", myTextFormat);
  21. addChild(myLabel);

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: sillicon on December 13, 2008

ooh man... you saved my frickin live!!! had a specific problem with the textfield class that could not be solved...

Posted By: vip4lyf on February 28, 2009

shouldn't this line: var myFont:Font = new MyFont();

be: var myFont:Font = new Font()

?

Posted By: chrisaiv on March 2, 2009

Not exaclty. MyFont() is name you assigned the font after importing it into the Library.

Posted By: crmedinar on June 6, 2009

Hi I have tried this but my label text disappeared !!

Please, a little hint ??

Many thanks !!

Posted By: crmedinar on June 6, 2009

Hi I have tried this but my label text disappeared !!

Please, a little hint ??

Many thanks !!

Posted By: chrisaiv on June 22, 2009

crmedinar: You'll have to be more specific. I suspect you're having problems with a particular Font but you'll have to give me more information. I'd suggest first trying a basic font like Verdana.

You need to login to post a comment.