Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to align text vertically?

New Here ,
Sep 14, 2010 Sep 14, 2010

I have Input Text box and the size is Width: 200 and Hight: 150. I need to align text vertically center using action script.

Please help me!

Thanks,

Jafy

TOPICS
ActionScript
7.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 14, 2010 Sep 14, 2010

Below is an example of centering. As for the XML, etc., I guess it is a different topic - for a new thread it is.

var textContainer:Sprite = new Sprite();
var g:Graphics = textContainer.graphics;
g.beginFill(0x80FF00);
g.drawRect(0, 0, 400, 300);
g.endFill();

var format:TextFormat = new TextFormat("Arial", 20, 0x0000FF, "bold");

var textField:TextField = new TextField();
textField.autoSize = TextFieldAutoSize.LEFT;
textField.defaultTextFormat = format;
textField.text = "This is the text!\nAnd it is center

...
Translate
LEGEND ,
Sep 14, 2010 Sep 14, 2010

TextField doesn't have vertical alignment. You need to place it into another container and align it relative to this container.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 14, 2010 Sep 14, 2010

You want to move the text field to align it with something? You can use the textHeight property of the field to get the height of the text in pixels. Divide that by 2 and you have it's center.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 14, 2010 Sep 14, 2010

Hi Friends Thanks for the reply.

Do you have any sample for this?

And I need one more help

1.       I am getting the content from XML and showing to the text box. If the content is more than the text field size then its hide the content. Please tell me how I adjust the height of the text box according to the XML content.

2.       I have some XML content with HTML links and loading this to another text box. I need to highlight the corresponding content(link) when mouse over.

Please help me!

Thanks,

Jafy

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 14, 2010 Sep 14, 2010

Below is an example of centering. As for the XML, etc., I guess it is a different topic - for a new thread it is.

var textContainer:Sprite = new Sprite();
var g:Graphics = textContainer.graphics;
g.beginFill(0x80FF00);
g.drawRect(0, 0, 400, 300);
g.endFill();

var format:TextFormat = new TextFormat("Arial", 20, 0x0000FF, "bold");

var textField:TextField = new TextField();
textField.autoSize = TextFieldAutoSize.LEFT;
textField.defaultTextFormat = format;
textField.text = "This is the text!\nAnd it is centered\nall over the place";
textField.x = (textContainer.width - textField.width) * .5;
textField.y = (textContainer.height - textField.height) * .5;


textContainer.addChild(textField);
addChild(textContainer);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 14, 2010 Sep 14, 2010
LATEST

Thanks lot Andrei1, now I have posted a new one for XML.

Please help me!

Jafy

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines