为什么 Flex AS3 TextArea Htmltext 会更改事件格式
这让我睡不着觉,我在这里添加了我的测试应用程序。只需复制并粘贴即可测试应用程序在单击“添加”时将格式良好的 html 文本添加到文本区域 然后,单击“go”时,我将此 html 文本移至另一个文本区域,我发现文本格式已更改,标签变得混乱。
我的最终目标是将 html 文本正则表达式转换为另一个接口的另一种格式。然而,这种混乱的标签让我头疼。
任何防止或纠正这种情况的解决方案将不胜感激。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()" xmlns:ns1="com.tree.*">
<mx:Script>
<![CDATA[
private function init():void {
originalTA.text='<TEXTFORMAT LEADING="-2">'+ '<P ALIGN="JUSTIFY">'+ '<FONT SIZE="26" COLOR="#9B0000" LETTERSPACING="0" KERNING="0"> some text </FONT> '+ '<FONT SIZE="26" COLOR="#BEBEBE"> some text </FONT> '+ '<FONT SIZE="26" COLOR="#9B0000" LETTERSPACING="0" KERNING="0"> some text </FONT>'+ '</P>'+ '</TEXTFORMAT>';
}
private function add():void {
viewDTA.htmlText=originalTA.text;
}
private function go():void {
htmlTA.text=viewDTA.htmlText;
}
]]>
</mx:Script>
<mx:HBox width="100%" height="100%">
<mx:Label text="input"/>
<mx:TextArea id="originalTA" height="100%" width="100%"/>
<mx:Button label="add" click="add()"/>
<mx:Label text="view"/>
<mx:TextArea id="viewDTA" height="100%" width="100%"/>
<mx:Button label="go" click="go()"/>
</mx:HBox>
<mx:HBox width="100%" height="100%">
<mx:Label text="html"/>
<mx:TextArea id="htmlTA" height="100%" width="100%"/>
</mx:HBox>
</mx:Application>
This is giving me no sleep, I've added my test application here. Just copy and paste to test the application adds well formatted html text to a text area on clicking 'add'
then on clicking 'go' I take this html text out to another Text area and I see the text has changed format where the tags get muddled up.
My end goal is to regex the html text out to another format for another interface. However this muddeling of tags is causing me headaches.
Any solutions to prevent or rectify this would be much appreciated.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()" xmlns:ns1="com.tree.*">
<mx:Script>
<![CDATA[
private function init():void {
originalTA.text='<TEXTFORMAT LEADING="-2">'+ '<P ALIGN="JUSTIFY">'+ '<FONT SIZE="26" COLOR="#9B0000" LETTERSPACING="0" KERNING="0"> some text </FONT> '+ '<FONT SIZE="26" COLOR="#BEBEBE"> some text </FONT> '+ '<FONT SIZE="26" COLOR="#9B0000" LETTERSPACING="0" KERNING="0"> some text </FONT>'+ '</P>'+ '</TEXTFORMAT>';
}
private function add():void {
viewDTA.htmlText=originalTA.text;
}
private function go():void {
htmlTA.text=viewDTA.htmlText;
}
]]>
</mx:Script>
<mx:HBox width="100%" height="100%">
<mx:Label text="input"/>
<mx:TextArea id="originalTA" height="100%" width="100%"/>
<mx:Button label="add" click="add()"/>
<mx:Label text="view"/>
<mx:TextArea id="viewDTA" height="100%" width="100%"/>
<mx:Button label="go" click="go()"/>
</mx:HBox>
<mx:HBox width="100%" height="100%">
<mx:Label text="html"/>
<mx:TextArea id="htmlTA" height="100%" width="100%"/>
</mx:HBox>
</mx:Application>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您为
TextArea.htmlText
属性设置值时,Flex 会自动插入与 CSS 样式中设置的 defaultTextFormat 相对应的附加 HTML 标记。为了解决此问题,我将创建一个新组件来扩展 TextArea 组件并重写
set htmlText
函数,以将原始文本存储在名为OriginalHTMLText
的新变量中,您可以稍后访问即可获取原始 HTML 文本。尝试以此为起点:
When you set a value to the
TextArea.htmlText
property Flex automatically inserts additional HTML markup corresponding to the defaultTextFormat set from the CSS styles.To get around this behavior, I would create a new component that extends the TextArea component and overrides the
set htmlText
function to store the original text in a new variable calledOriginalHTMLText
you can access later to get the original HTML text.Try using this as a starting point: