开发者

AS3 Scale Text Function Causing Conflict With Textfield HTML Format

开发者 https://www.devze.com 2023-03-17 01:37 出处:网络
Hello Guys I am using the below function to scale dynamic font size at run time as thus: function scaleTextToFitInTextField( txt : TextField ):void{

Hello Guys I am using the below function to scale dynamic font size at run time as thus:

function scaleTextToFitInTextField( txt : TextField ):void{
 var f:TextFormat = txt.getTextFormat();
 f.size = ( txt.width > txt.height ) ? txt.width : txt.height;
 txt.setTextFormat( f );

 while ( txt.textWidth > txt.width - 4 || txt.textHeight > txt.height - 6 ){               
    f.size = int( f.size ) - 1;
    txt.setTextFormat( f );
}
}

scaleTextToFitInTextField( tf );
// tf is a dynamic multiline textfield on stage with dimension 150x150

The idea is that when the textfield is populated with external content, it reduces the font size to fit all the text into the texfield. This work so far.

My biggest problem now is that this function interferes with the textfield html formatting. For instance; I Load an external html:

<font size="-2">this text is way</font><br><font size="+5">TOO BIG</font><br>to fit in this box, but I'll give it a try!

With the scale function applied to the textfield, the html formatting (size variations) does not work, b开发者_如何学Pythonut if I remove the scale function, it does.

Ideally, I want to be able to scale the font if text is too much to fit and be able to apply html format as well.

Somebody pls help. I am using CS5

Many thanks.


It may work if you wrap the htmlText in <![CDATA[]]>:

<![CDATA[<font size="-2">this text is way</font><br><font size="+5">TOO BIG</font><br>to fit in this box, but I'll give it a try!]]>

Otherwise, you could try wrapping the TextField in a Sprite and scale the Sprite instead? How do you scale a dynamic textfield in flash from the center point using as3?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号