The following example demonstrates how to create a button with a multiline label using the textField property to access the Button instance’s internal TextField object.
Full code after the jump.
// ActionScript 3.0 // Import the required component classes. import fl.controls.Button; // Create a new TextFormat object and set the align property to "center". var myTextFormat:TextFormat = new TextFormat(); myTextFormat.align = TextFormatAlign.CENTER; /* Create a new Button component instance, set the textFormat style to the TextFormat object created earlier, and add the button to the display list. */ var myButton:Button = new Button(); myButton.label = "The quick brown fox jumped over the lazy dog"; myButton.textField.wordWrap = true; myButton.setStyle("textFormat", myTextFormat); myButton.setSize(120, 60); myButton.move(10, 10); addChild(myButton);
{ 1 comment… read it below or add one }
hey , this is great helpful code but when i rollover the button it narrows the textfield width every time, creating a strange effect. its like flash is decreasing the wordwrap limit or text field width every time rollover occurs. is there a fix for this?