Search This Blog

Mind freaker Stuff

Please Visit my new blog http://www.mindfreakerstuff.com for new articles related to web and mobile designing.

Sunday, November 27, 2011

Vertical Text Alignment for Dynamic Text Field Flash Action script 2

This is a simple Hack for flash Dynamic Text Field  With AS2 Where  Vertical Text Align is not supported.
Instated of setting Text Vertically  align we can position Text Field vertically Center by Y axis Position  .

Steps : Add Follwing code in on layer action

//To get Empty text field height 
blank_height  = TextField_instance._height;


//Setting Text to text field 
TextField_instance.text = "This text is vertically align";

//Adding autosize to text field  
TextField_instance.autoSize = "center";


//for Vertical Alignment
TextField_instance._y = TextField_instance._y + (blank_height  -TextField_instance._height) / 2;

Thanks,
Cheers....  :)

5 comments:

  1. Thanks for this! Works like a charm :)

    ReplyDelete
  2. You need to take in account the fact that textHeight might be smaller than the textfield height therefore the correct code for the last line is:

    TextField_instance._y = TextField_instance._y + (blank_height -TextField_instance.textHeight) / 2;

    ReplyDelete
  3. Thanks for indicating the way :)

    ReplyDelete