AS3 htmlText显示标签

时间:2011-05-20 13:02:06

标签: actionscript-3 textfield htmltext

我有一个用AS3创建的文本字段:( theDesc是通过函数传递的参数)

var productDescTxt:TextField = new TextField();
productDescTxt.htmlText = theDesc;  
productDescTxt.multiline = true;
productDescTxt.wordWrap = true;
productDescTxt.embedFonts = true;
productDescTxt.setTextFormat(productInfoTF);
productDescTxt.x = 10;
productDescTxt.y = productNameTxt.y+productNameTxt.textHeight+15;
productDescTxt.width = 325;
holder.productsTab.addChild(productDescTxt);

theDesc是包含字符编码的html内容:

前:

<p><strong>6.1 oz cotton at an affordable price</strong></p>

问题是textField正在显示每个字符。 <p><strong>等。

我的目的是否需要额外的编码?

3 个答案:

答案 0 :(得分:0)

查看此页面的来源并找到以下行:

&lt; weare the something&gt;

这个答案框与flash textField htmlText函数几乎相同 更多关于flash中的htmlText posibilieties:TextField – available html tags

答案 1 :(得分:0)

看起来你是从某个服务器上获得的,不是吗?您需要手动更改&lt; <&gt;>。例如。在PHP中(如果您的应用程序的服务器部分是用PHP编写的),html_decode()函数将替换所有人。我不知道AS3中有类似的功能。

但是,我可以告诉你一个小技巧:

var tempField:TextField = new TextField();
tempField.htmlText = theDesc;  
var productDescTxt:TextField = new TextField();
//...
productDescTx.htmlText = tempField.text;  
holder.productsTab.addChild(productDescTxt);

将为你做html_decode()!希望有所帮助!

答案 2 :(得分:0)

您不希望HTML特殊字符用于htmlText值,转义它们会看到此答案Unescape (decode) HTML characters from string in Flex

相关问题