Search code examples
actionscript-3stylesheetcss

Line-height in actionscript stylesheets


I'm having problems with figuring out the ability to use css stylesheets in actionscript.

I'm trying to verticaly center text inside a textfield. I tried to use line-height but it doesn't do a thing. Does anyone know a solution to this?

Here's my code:

var style:StyleSheet = new StyleSheet();
style.parseCSS("a{color:#" + color + "; fontSize:" + fontSize + "; font-family: " + font + "; line-height: " + stageheight + "; text-align: center;}");

this is the link where i test my flash video:

http://www.stevevo.sin.khk.be/2SFlashGenerator/flashTest.php

You'll notice that other property's like color, fontsize and font are adjustable so the stylesheet itself works fine only line-height doesnt work.


Solution

  • There is no support for vertical padding, margins and alignment in Flash CSS, so you will have to center the TextField instead of the text:

    1. set textField.autoSize = TextFieldAutoSize.LEFT; If you then specify width as well, the TextField will resize only in height.

    2. set textField.y = (textField.parent.height - textField.height) * .5;

    The latter will place the TextField at the vertical center of its parent DisplayObject.