我可以访问 Flex 中 textArea 中的 htmlText setter 代码吗?

发布于 2024-09-24 15:11:50 字数 407 浏览 5 评论 0原文

问候, 我可以看到,当我在 textarea 控件中设置 htmlText 时,text 属性包含文本的 html 免费版本。所以有一个解析器从内容中提取 html,这对我的目的非常有用。 不过基于flex源码,html的设置是在UITextField.as中完成的,是TextArea的textfield成员的类型。完成这项工作的线路是: super.htmlText = 值; 在功能上 override public function set htmlText(value:String):void

尝试遵循类层次结构,我最终得到了 FlexTextField 类,它扩展了 flash 播放器的文本字段类。

看来我所追求的功能是在 Flash 播放器中。那么有什么方法可以访问这个html清理功能呢?我在这里错过了什么吗?

此致 塞雷夫

Greetings,
I can see that when I set htmlText in a textarea control, the text property contains the html free version of the text. So there is a parser somewhere that is ripping of html from the content, which would be very usefull for my purposes.
However, based on the flex source code, the setting of html is done in UITextField.as, which is the type of the textfield member of TextArea. The line that does the work is:
super.htmlText = value;
in function
override public function set htmlText(value:String):void

Trying to follow the class hieararchy, I end up in FlexTextField class, which extends flash player's textfield class.

It appears the functionality I am after is in flash player. So is there any way of accessing this html cleaning function? Am I missing something here?

Best Regards
Seref

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪你到最终 2024-10-01 15:11:51

不可以,无法访问 Flash Player 本机类中的代码。

但是,您应该能够使用正则表达式轻松解析内容中的所有 HTML 标签。

虽然未经测试,但这里有一个选项出现在谷歌中。您可以在 Flex 中使用它。所以,你也许可以这样做:

var regEx : RegExp = new RegExp('<(.|\n)*?>');
var noHTMLText = htmlText.replace(regEx , '');

当然,这是在浏览器中编写的。 有关 Flex 中的正则表达式的详细信息

Nope, there is no way to access code in the Flash Player native classes.

However, you should be able to use a Regex to easily parse out all HTML Tags in your content.

Although, not tested, here is one option that came up in Google. You can just use that in Flex. So, you can probably do something like this:

var regEx : RegExp = new RegExp('<(.|\n)*?>');
var noHTMLText = htmlText.replace(regEx , '');

Of course, this was written in the browser. More info on Regex in Flex.

不爱素颜 2024-10-01 15:11:50

如果正则表达式失败,您可能需要检查以下内容:

var t:String = "asd <span>This is <font>some</font> text <b> :) </b> </span> \nand more";
function stripTags(x:XML):String {
  var t:String = "";
  var children:XMLList = x.children();
  var child:XML;
  for(var i:Number = 0; i < children.length(); i++){
    child = children[i];
    if(child.nodeKind() == "text")
      t += child.toString();
    else if(child.nodeKind() == "element")
      t += stripTags(child);
  }
  return t;
}
var x:XML = new XML("<root>" + t + "</root>");
XML.ignoreWhitespace = false;
var s:String = stripTags(x);
trace(s);

PS:我尚未测试此 ActionScript 代码,这里是我测试并发现有效的等效 JavaScript 代码。我认为它可以在 ActionScript 中工作,因为两者都遵循 ECMAScript。

var t = "asd <span>This is <font>some</font> text <b> :) </b> </span> \nand more";
function stripTags(str){
  function strip(x){
    var t = "";
    var children = x.children();
    var child;
    for(var i = 0; i < children.length(); i++){
      child = children[i];
      if(child.nodeKind() == "text")
        t += child.toString();
      else if(child.nodeKind() == "element")
        t += strip(child);
    }
    return t;
  }
  var xml = new XML("<root>" + str + "</root>");
  XML.ignoreWhitespace = false;
  return strip(xml);
}
var s = stripTags(t);
console.log(s);

输出:

asd This is some text :)  
and more

In case regex fails you, here is something you might want to check out:

var t:String = "asd <span>This is <font>some</font> text <b> :) </b> </span> \nand more";
function stripTags(x:XML):String {
  var t:String = "";
  var children:XMLList = x.children();
  var child:XML;
  for(var i:Number = 0; i < children.length(); i++){
    child = children[i];
    if(child.nodeKind() == "text")
      t += child.toString();
    else if(child.nodeKind() == "element")
      t += stripTags(child);
  }
  return t;
}
var x:XML = new XML("<root>" + t + "</root>");
XML.ignoreWhitespace = false;
var s:String = stripTags(x);
trace(s);

PS: I haven't tested this ActionScript code, here is the equivalent JavaScript code that I tested and found working. I assume it would work in ActionScript since both follow ECMAScript.

var t = "asd <span>This is <font>some</font> text <b> :) </b> </span> \nand more";
function stripTags(str){
  function strip(x){
    var t = "";
    var children = x.children();
    var child;
    for(var i = 0; i < children.length(); i++){
      child = children[i];
      if(child.nodeKind() == "text")
        t += child.toString();
      else if(child.nodeKind() == "element")
        t += strip(child);
    }
    return t;
  }
  var xml = new XML("<root>" + str + "</root>");
  XML.ignoreWhitespace = false;
  return strip(xml);
}
var s = stripTags(t);
console.log(s);

output:

asd This is some text :)  
and more
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文