PDA

View Full Version : adjust button dimension to text



rafnews
February 13th, 2008, 10:01 AM
Hi,
i have a dynamic text field onto which one, i should have a buttonclip.

however, as the text into dynamic field changes size quite often, i would like to automatically adjust the size of button to the dynamic text field.

I've tried that :
mybutton.Height = mytext.height;
mybutton.Width = mytext.width;
mybutton.x = mytext.x;
mybutton.y = mytext.y;

but i does not work well... button does not update to mytext size.
before i tried :
mybutton.height = mytext.height;
mybutton.width = mytext.width;

but in this case, width and height of mybutton = 0;

so any idea ?

thx.

Felixz
February 13th, 2008, 04:17 PM
mybutton.myGraphic.height = mybutton.mytext.height;
mybutton.myGraphic.width = mybutton.mytext.width;
myGraphic and mytext are children of mybutton
and set this after text input.
U can also use (must be in ur button class file)
function set text(t:String) {
this.mytext.text=t;
this.myGraphic.height = this.mytext.height;
this.myGraphic.width = this.mytext.width;
}Usage:

mybutton.text="foo";