The following example shows how you can display a background color on a Flash ActionScript 3.0 Label control by setting the background and backgroundColor properties on the Label control’s internal TextField.

Full code after the jump.

// ActionScript 3.0
import fl.controls.Label;
 
var myLabel:Label = new Label();
// add background color to internal text field.
myLabel.textField.background = true;
myLabel.textField.backgroundColor = 0xDDDDDD;
addChild(myLabel);
Tagged with:
 

5 Responses to Displaying a background color on a Label control in Flash

  1. Geert says:

    What’s this
    import fl.controls.Label ???

    If I use
    import mx.controls.Label;

    I get
    1178: Attempted access of inaccessible property textField through a reference with static type mx.controls:Label.

  2. Bruce says:

    try using the namespace mx_internal

    use namespace mx_internal;  // don't forget to import it
    (l.mx_internal::getTextField() as UITextField).background = true;
    (l.mx_internal::getTextField() as UITextField).backgroundColor =0xDDDDDD
  3. Chris says:

    thanks Peter , it helps me a lot

  4. NOOK says:

    Hello Peter.
    I’m a newbie in actionscript\flex, so can u hepl me with that please?
    I need to change background colour of the Label, I try to use Your script, and got an error:
    1151: Conflict in myLabel on the internal namespace

    What I do wrong?
    Thanks.

Leave a Reply

Your email address will not be published.

You may 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="" highlight="">

Spam Protection by WP-SpamFree