Creating multiline Button component labels in Flash with ActionScript 3.0

by Peter deHaan on November 25, 2008

in Button

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 }

1 luke 02.24.09 at 7:16 pm

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?

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: