2012-03-16 12 views
1

私はビューア(都市、州)の地理位置を取得するフラッシュアプ​​リケーションを作成し、私はどのように私はそれが名前の大きさに応じて持っているコンテナに収まるようにフォントを小さくすることができるかを把握しようとしている都市のたとえば、「Detroit」は適合しますが、「Los Angeles」は小さいフォントである必要があります。flash:単語の大きさに応じてテキストサイズを変更しますか?

答えて

0
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(); 
関連する問題