【问题标题】:AS3 htmlText is showing tagsAS3 htmlText 显示标签
【发布时间】:2011-05-20 13:02:05
【问题描述】:

我有一个使用 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>

我需要做额外的编码吗?

【问题讨论】:

  • theDesc 在你设置的地方是什么样子的?
  • 它被作为一个字符串传递,就像我的例子一样。
  • 喜欢这个 <p><strong>6.1 盎司棉花,价格实惠</strong></p>?
  • 是的。像我的例子一样,一个字符一个字符。
  • 那你为什么不用服务器端语言来做 html_decode 或者直接输入 xml 或字符串呢?

标签: actionscript-3 textfield htmltext


【解决方案1】:

看起来您是从某个服务器获取的,不是吗?您需要手动将&amp;lt; 更改为&lt;,将&amp;gt; 更改为&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】:

    查看该页面的源代码并找到这一行:

    此答案框的作用与 flash textField htmlText 功能几乎相同。
    更多关于 Flash 中的 htmlText 可能性:TextField – available html tags

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多