Displaying a background color on a Label control in Flash

by Peter deHaan on December 4, 2008

in Label

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);

{ 4 comments… read them below or add one }

1 Geert 02.16.09 at 2:11 am

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 Peter deHaan 02.18.09 at 9:11 am

Geert,

The fl.controls.Label is the Flash Authoring/ActionScript 3.0 Label control.
The mx.controls.Label is the Flex SDK/ActionScript 3.0 Label control.

Peter

3 Bruce 04.08.09 at 12:06 pm

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
4 Chris 10.08.09 at 4:03 pm

thanks Peter , it helps me a lot

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: