HTML标记不';调整文本大小时无法工作

HTML标记不';调整文本大小时无法工作,html,flash,actionscript,resize,textfield,Html,Flash,Actionscript,Resize,Textfield,我有一个动态填充的文本字段。如果填充的文本不适合文本字段,则会调整文本的大小。HTML标记在动态填充的文本中正常工作,但仅当文本未调整大小时。HTML标记在调整大小的文本中被忽略。有什么想法吗 文本字段的代码: import flash.text.TextFormat; import flash.text.Font; // function setDesc(str:String):void{ var fmtD:TextFormat; var

我有一个动态填充的文本字段。如果填充的文本不适合文本字段,则会调整文本的大小。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;
    }    
} 
导入flash.text.TextFormat;
导入flash.text.Font;
//
函数setDesc(str:String):void{
var-fmtD:TextFormat;
var cfmtD:TextFormat=this.desc_txt.getTextFormat()=null?this.desc_text.defaultTextFormat:this.desc_txt.getTextFormat();
变量大小:int=22;
desc_txt.htmlText=str;
而(大小>10&&sizeD255){
大小--;
fmtD=新文本格式(descFont.fontName,大小,0x000000,false,false,false);
desc_txt.htmlText=str;
desc_txt.setTextFormat(fmtD);
} 
}
填充文本字段的代码:

    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;
    }    
} 
函数openDialog(e:MouseEvent){
dialog_window.doOpen();
开关(e.currentTarget.name){
案例“btn_结构”:
对话框_window.setTitle(“业务结构:”);
dialog_window.setDesc(“本主题讨论业务领域的基本结构”);
打破
案例“btn_服务”:
对话框_window.setTitle(“提供的服务:”);
dialog_window.setDesc(“本主题提供有关客户计费服务单元提供的服务的信息”);
打破
}    
} 

尝试将while循环中的最后两行更改为:

desc_txt.defaultTextFormat = fmtD;
desc_txt.htmlText = str;
你可以阅读更多关于

编辑:

我只是使用您的代码设置了这个简单的示例,文本格式(字体类型和大小)和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);
导入flash.text.TextField;
导入flash.text.TextFormat;
变量大小:uint=22;
var desc_txt:TextField=new TextField();
addChild(desc_txt);
var str:String=“本主题讨论业务区域的基本结构。本主题讨论业务区域的基本结构。本主题讨论业务区域的基本结构。本主题讨论业务区域的基本结构。”;
var-fmtD:TextFormat;
fmtD=新文本格式(“Verdana”,大小,0x000000,假,假,假);
desc_txt.width=450;
描述高度=150;
desc_txt.wordWrap=true;
desc_txt.defaultTextFormat=fmtD;
desc_txt.htmlText=str;
var maxHeight=150;
跟踪(大小+“-”+desc_txt.textHeight);
而(尺寸>10&&sizeDmaxHeight)
{
跟踪(“-->内部while循环”);
大小--;
fmtD=新文本格式(“Verdana”,大小,0x000000,假,假,假);
desc_txt.defaultTextFormat=fmtD;
desc_txt.htmlText=str;
}
跟踪(大小+“-”+desc_txt.textHeight);

255是文本框的高度。255是文本框的高度。我的问题是,可能有太多的文本无法放入文本框,因此它会被调整大小。当这种情况发生时,HTML标记不起作用。在您的示例中,文本不会换行,因此当您向字符串添加更多内容时,它会被截断。我的文本框是455.40W乘255H。我的错是,我对TextField.textHeight的理解错了。不管怎样,我用wordwrap修复了我的简单代码示例,它在调整大小和不需要调整大小时都工作得很好。请确保使用desc_txt.defaultTextFormat=fmtD;代替setTextFormat(fmtD);每次都是。谢谢你!尝试了几次,但我终于能够将您的代码转换到我的代码中。