actionscript 3 - How do I set up my multiline wordWrap TextField to automatically resize its width when height is set? -
i want create textfield extension that: when width set, automatically resize height content of text. easy done autosize left, word wrap true, multiline true. when height set, automatically resize width content of text. here problem.
when both width , height set aren't case interested in.
i've tried several things off internet, stumped.
general solution impossible, if text field contains many newlines display within given height, no matter width assign, text field unable display lines. partial solution presented greetification, lacks features 1 should aware of. first, no matter do, should not set height value less font height, or text field not able display single line. second, if wordwrap
set false, , multiline
true, resultant textwidth
largest desirable width text field, if adjust width greetification advises, stop once reach recorded textwidth
, further increases pointless.
function setheight(newheight:number):void { var tw:number; var th:number; if (mytextfield.wordwrap) { mytextfield.wordwrap=false; tw=mytextfield.textwidth; th=mytextfield.textheight; mytextfield.wordwrap=true; } else { tw=mytextfield.textwidth; th=mytextfield.textheight; } if (newheight<th) newheight=th+2; // below mytextfield.height = newheight; while((mytextfield.textheight > mytextfield.height)&&(mytextfield.width<tw)) { mytextfield.width += 100; } if (mytextfield.width>tw) mytextfield.width=tw+2; // "2" depends on text format // , other properties, either play or assume number big enough }
Comments
Post a Comment