2012-07-23 1 views
0

동적으로 채워지는 텍스트 필드가 있습니다. 채워진 텍스트가 텍스트 필드에 맞지 않으면 텍스트의 크기가 조정됩니다. HTML 태그는 텍스트가 크기가 조정되지 않는 경우에만 동적으로 채워진 텍스트에서 올바르게 작동합니다. HTML 태그는 크기가 조정 된 텍스트에서 무시됩니다. 아이디어가 있으십니까? 텍스트 필드에 대한텍스트 크기가 조정 된 HTML 태그가 작동하지 않습니다.

코드 :

import flash.text.TextFormat; 
    import flash.text.Font; 
    // 
    function setDesc(str:String):void{ 
     var fmtD:TextFormat; 
     var cfmtD:TextFormat = this.desc_txt.getTextFormat()==null ? this.desc_text.defaultTextFormat : this.desc_txt.getTextFormat(); 
     var sizeD:int = 22; 
     desc_txt.htmlText = str; 
     while(sizeD>10 && sizeD<23 && desc_txt.textHeight>255){ 
     sizeD--; 
     fmtD = new TextFormat(descFont.fontName,sizeD,0x000000,false, false,false); 
     desc_txt.htmlText = str; 
     desc_txt.setTextFormat(fmtD); 
     } 
} 

코드는 텍스트 필드를 채 웁니다 :

function openDialog(e:MouseEvent){ 
    dialog_window.doOpen(); 
     switch(e.currentTarget.name){ 
     case "btn_structure": 
      dialog_window.setTitle("Business Structure:"); 
      dialog_window.setDesc("This topic discusses the <b>basic</b> structure of the business area."); 
     break; 
     case "btn_services": 
      dialog_window.setTitle("Services Provided:"); 
      dialog_window.setDesc("This topic provides <i>information</i> about the services offered by the Client Billing Services unit."); 
     break; 
    }  
} 

답변

0

동안 루프에 내부을 마지막 두 줄을 변경해보십시오 :

desc_txt.defaultTextFormat = fmtD; 
desc_txt.htmlText = str; 

당신은 더

working with html tags and the as3 TextFormat class here에 대한 편집을 읽을 수 있습니다 : 난 그냥 굵은 코드 및 텍스트 서식 모두 (글꼴의 종류와 크기)와 html 태그의 비트를 사용하여이 간단한 예제를 (설정

및 기울임 꼴)은 완벽하게 작동합니다.

import flash.text.TextField; 
import flash.text.TextFormat; 

var sizeD:uint = 22; 
var desc_txt:TextField = new TextField(); 
addChild(desc_txt); 

var str:String = "This topic <i>discusses</i> the <b>basic</b> structure of the business area. This topic <i>discusses</i> the <b>basic</b> structure of the business area.This topic <i>discusses</i> the <b>basic</b> structure of the business area. This topic <i>discusses</i> the <b>basic</b> structure of the business area."; 

var fmtD:TextFormat; 
fmtD = new TextFormat("Verdana",sizeD,0x000000,false, false,false); 

desc_txt.width=450; 
desc_txt.height=150; 
desc_txt.wordWrap=true; 

desc_txt.defaultTextFormat = fmtD; 
desc_txt.htmlText = str; 

var maxHeight = 150; 

trace(sizeD+" - "+ desc_txt.textHeight); 
while(sizeD>10 && sizeD<23 && desc_txt.textHeight>maxHeight) 
{ 
    trace("--> inside while loop"); 
    sizeD--; 
    fmtD = new TextFormat("Verdana",sizeD,0x000000,false, false,false); 
    desc_txt.defaultTextFormat = fmtD; 
    desc_txt.htmlText = str; 

} 
trace(sizeD+" - "+desc_txt.textHeight); 
+0

이 경우 HTML 태그는 작동하지만 크기 조정은 수행되지 않습니다. –

+0

이상한, 제 편집을 확인하고 도움이되는지 확인하십시오. – danii

+0

255는 텍스트 상자의 높이입니다. –

관련 문제