Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lynxerzhang/2516117 to your computer and use it in GitHub Desktop.
Save lynxerzhang/2516117 to your computer and use it in GitHub Desktop.
Bit101's Text Component is Unable set the TextFormat?
//I use Bit101's Component framework(Window, Text, PushButton) to create a Alert Component
/**
* create a window and set size (this window couldn't be drag)
*/
var alert:Window = new Window(this, 0, 0, "Alert");
alert.draggable = false;
alert.setSize(300, 200);
/*
* set text to show the alert's info
*/
var t:Text = new Text(alert, 0, 0, "Bit101 component");
t.selectable = false;
t.editable = false;
t.width = alert.width;
t.height = alert.height - 60;
var format:TextFormat = t.textField.getTextFormat();
format.align = TextFormatAlign.CENTER;
format.size = 12; //set the size is 12
format.bold = true;//set the font is bold
/**
* we found only 'align' set is work, the 'bold' and 'size' not work
*
* because 't.textField.getTextFormat() return a textformat
* that doesn't same as Text Component's internal TextFormat
*
* and the Component redrawn on the next frame, the 'size' set and 'bold' set will be reset
*/
t.textField.defaultTextFormat = format;
t.textField.setTextFormat(format);
/**
* create a button position it
*/
var ok:PushButton = new PushButton(alert, 0, 0, "ok");
ok.x = (alert.width - ok.width) * .5;
ok.y = (alert.height - ok.height) - ok.height - 10;
/**
* reposition window
*/
alert.x = (stage.stageWidth - alert.width) * .5;
alert.y = (stage.stageHeight - alert.height) * .5;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment