Jump to content
Search Community

Repeating background for Textfield

iTech test
Moderator Tag

Recommended Posts

Is there any way to repeat a background for a textfield?

 

In HTML/CSS, you can have an image for the left side, repeating center image, and then another image for the right side so that if the text inside every became larger or smaller, it would scale accordingly.

Link to comment
Share on other sites

TextFields can only have a solid background color as far as I am aware. You'll need to look into using a wrapper class for this I think. It's not really something we deal with here, but here's a basis you could start from perhaps:

package {
  
  import flash.display.Sprite;
  import flash.text.TextField;
  
  public class TextFieldPlus extends Sprite {
    
    public var textfield:TextField;
    private var bg:Sprite;
    
    public function TextFieldPlus() {
      bg = new Sprite();
      addChild(bg);
      textfield = new TextField();
      addChild(textfield);
    }
    
    public function get text():String {
      return textfield.text;
    }
    
    public function set text(value:String):void {
      textfield.text = value;
      refresh();
    }
    
    public function refresh():void {
      // draw in whatever background images you need here
      bg.graphics.clear();
      bg.graphics.beginFill(0xFF0000);
      bg.graphics.drawRect(0, 0, textfield.width, textfield.height);
      bg.graphics.endFill();
    }
    
  }

}
var tf:TextFieldPlus = new TextFieldPlus();
addChild(tf);
tf.textfield.autoSize = TextFieldAutoSize.LEFT;
tf.text = "Some text";
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...