1
我做了一個Flash應用程序,獲取查看器(城市,州)的地理位置,我試圖弄清楚如何使字體更小以適應容器中的內容,這取決於名稱的大小的城市是。例如,「底特律」可能適合,但「洛杉磯」可能需要是較小的字體。flash:根據單詞的大小更改文字大小?
我做了一個Flash應用程序,獲取查看器(城市,州)的地理位置,我試圖弄清楚如何使字體更小以適應容器中的內容,這取決於名稱的大小的城市是。例如,「底特律」可能適合,但「洛杉磯」可能需要是較小的字體。flash:根據單詞的大小更改文字大小?
TextField.prototype.shrinkToFit = function(mn)
{
var fmt = this.getTextFormat();
var pt = fmt.size;
/* add an extra few pixels to text width to be sure (there seem to be
some inherent margins)*/
while(this.textWidth + fmt.leftMargin + fmt.rightMargin + 4 > this._width){
fmt.size = --pt;
this.setTextFormat(fmt);
// break the loop if we've reached a specified minimum font size
if(mn != null && pt == mn) {
break;
}
}
return pt;
};
實例:
this.createTextField("tf",10,20,20,200,20);
this.tf.multiline = false;
this.tf.wordWrap = false;
this.tf.setNewTextFormat(new TextFormat("_sans",18));
this.tf.text = "Ten thousand thundering typhoons";
this.tf.shrinkToFit();