TextField! I said… DON’T SCROLL WITH ME!!

Já alguma vez se deparam com a seguinte situação?

Criam um TextField com o texto multi linha, seleccionável  e com autoSize. Tudo porreiro até que resolvem seleccionar o texto até o fim e por mania do flash player este faz scroll de uma linha. Argh! F******! :(

Então mas se a opção autoSize é diferente de NONE não devia este aumentar as dimensões do Display Object até caber todo o texto?

Claro que devia, mas isso só acontece se o espaçamento entre linhas (leading) for muito pequeno. Ou seja, o flash player considera a altura do texto até ao último pixel do último caracter mas no entanto para calcular se deve existir scroll vertical ou não este entra com o leading depois da última linha.
A mim parece-me bug mas no entanto não encontrei nada no bug tracker sobre este caso especifico... deve ser feature. :)

Exemplo:

Actionscript:
var tf:TextField = new TextField();
var format:TextFormat    =    new TextFormat();
format.leading    =    2;

tf.autoSize = TextFieldAutoSize.LEFT;
tf.multiline = true;
tf.wordWrap    =    true;
tf.defaultTextFormat    =    format;
tf.mouseWheelEnabled    =    false;
tf.selectable = true;
tf.width = 400;
tf.text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum.";
addChild(tf);

Qual a solução (a.k.a workaround)?

  • Diminuir o leading para <= 1. :D
    ou
  • Medir o TextField, mudar o autoSize para NONE e redimensionar somando os pixeis de leading.
    A parte chata é que é sempre necessário fazer isto quando o texto for mudado.

    Actionscript:
    var aux:Number = tf.height    +    tf.defaultTextFormat.leading;
    tf.autoSize    =    flash.text.TextFieldAutoSize.NONE;
    tf.height    =    aux;

Haverá outra solução?

Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]