DrElvisToad
09-19-2008, 05:08 PM
I'm trying to explicitly set the width of a label so that it stretches across the entire stage and has a dark background. No matter what I do, I just can't get the width to set. It always remains the same as the width of the text.
Here's the code:
package {
import flash.events.*;
import flash.display.Sprite;
import fl.controls.Label;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.display.Stage;
import flash.text.TextFormat;
public class Overlay extends Label {
public function Overlay(){
super();
addEventListener(Event.ADDED_TO_STAGE, onAdded);
autoSize = TextFieldAutoSize.LEFT;
var format:TextFormat = new TextFormat();
format.font = "Arial";
format.color = 0xFFFFFF;
format.size = 12;
format.underline = false;
setStyle("textFormat", format);
}
//using ADDED_TO_STAGE so I can get a valid reference for the stage's width
private function onAdded(evt:Event){
width = stage.stageWidth;
height = textField.textHeight+10;
trace(width + " "+ stage.stageWidth ); // traces "550 550" but the label still appears only as wide as its text
}
}
}
even if I try setting the width to a hard-coded number like 5000 it still remains only as wide as the text. anyone encountered this? is there a fix? thanks!
Here's the code:
package {
import flash.events.*;
import flash.display.Sprite;
import fl.controls.Label;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.display.Stage;
import flash.text.TextFormat;
public class Overlay extends Label {
public function Overlay(){
super();
addEventListener(Event.ADDED_TO_STAGE, onAdded);
autoSize = TextFieldAutoSize.LEFT;
var format:TextFormat = new TextFormat();
format.font = "Arial";
format.color = 0xFFFFFF;
format.size = 12;
format.underline = false;
setStyle("textFormat", format);
}
//using ADDED_TO_STAGE so I can get a valid reference for the stage's width
private function onAdded(evt:Event){
width = stage.stageWidth;
height = textField.textHeight+10;
trace(width + " "+ stage.stageWidth ); // traces "550 550" but the label still appears only as wide as its text
}
}
}
even if I try setting the width to a hard-coded number like 5000 it still remains only as wide as the text. anyone encountered this? is there a fix? thanks!