A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: dynamicly center text box

  1. #1
    Senior Member
    Join Date
    Jul 2002
    Location
    New Mexico
    Posts
    101

    dynamicly center text box

    I need to keep a text box centered in the middle of the stage (horizontaly) no matter how wide the text box is (it will get bigger and smaller dynamically).


    I also need:

    How can I get a dynamic text box to always display the text at the bottom?
    Similar to the "align bottom" with a cell in a table.


    any help would be great.
    Beyond Flash
    Your one stop web shop
    http://www.beyondflash.net

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    The basic forumula for keeping something centered is:

    thing._x = (Stage.width - thing._width)/2;

    or, if you've precomputed the center coordinate, you can use:

    centerCoordinate = Stage.width/2;
    thing._x = centerCoordinate - thing._width/2;

    If the text box is contained inside a movieclip, you can use the movieclip width. Otherwise, you can set the textfield to autosize and use the textWidth property instead of thing._width.

    The basic forumula for keeping something bottom-aligned is:

    thing._y = bottomCoordinate - thing._height;

    Again, you can either contain the textfield in a movieclip, and use the movieclip height, or you can set the textfield to autosize and use the textHeight property.

  3. #3
    Senior Member
    Join Date
    Jul 2002
    Location
    New Mexico
    Posts
    101
    How would I go about using the texthight property?
    Beyond Flash
    Your one stop web shop
    http://www.beyondflash.net

  4. #4
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Let's say your textfield is called myText.

    When you initialize it, you set autoSize to true:

    myText.text = 'initial text';
    myText.autoSize = true;


    When you change it, the textHeight property will tell you how tall it is.

    myText.text = 'changed text';
    myText._y = 200 - myText.textHeight;

  5. #5
    Senior Member
    Join Date
    Jul 2002
    Location
    New Mexico
    Posts
    101
    Got it
    Thank you very much!!
    Beyond Flash
    Your one stop web shop
    http://www.beyondflash.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center