Resizable Button with background in flash CS4
I want to create a button which resize dynamically with content. to achieve this, I created a MovieClip in library and added four layers into it namely - text, bg, shadow and border.
Problem I'm having is, if I make textfield autosize, only textfield resizes and others stuff remain as it is. if I calculate width required using xxxLineMetrics function and apply it to Button, background resizes properly but textfield also stretches with them and looks ugly.
I want backgrounds(sibling of textfield) resize properly with textfield so button looks nice with resized background and normal autosized textfield.
I hope u guys got what I want...any help appreciated...
T开发者_StackOverflow中文版hanks,
you should apply the calculated width to the bg movieclip only and not to the whole movieclip. Because this will change the textfield's width too.
so try something like this:
txt.autoSize = TextFieldAutoSize.LEFT;
txt.text = "label";
btn.bg.width = txt.width;
you can try the code below:
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
/**
* class represents the MyButton Movieclip in your library containing a dynamic
* textfield with instancename txt
* and a background movieclip with instance name bg
*/
public class MyButton extends MovieClip
{
public var txt : TextField;
public var bg : MovieClip;
public function MyButton(label : String)
{
txt.autoSize = TextFieldAutoSize.LEFT;
txt.text = label;
bg.width = txt.width;
}
}
}
精彩评论