flash:根据单词的大小更改文本大小?
我制作了一个flash应用程序,它可以获取观测者(城市、州)的地理位置,我正试图找出如何根据城市名称的大小将字体变小以适合我的容器。例如,“Detroit”可能合适,但“Los Angeles”可能需要较小的字体flash:根据单词的大小更改文本大小?,flash,actionscript-2,Flash,Actionscript 2,我制作了一个flash应用程序,它可以获取观测者(城市、州)的地理位置,我正试图找出如何根据城市名称的大小将字体变小以适合我的容器。例如,“Detroit”可能合适,但“Los Angeles”可能需要较小的字体 TextField.prototype.shrinkToFit = function(mn) { var fmt = this.getTextFormat(); var pt = fmt.size; /* add an extra few pixels to
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();