【问题标题】:Prevent copying style from one flex textArea to another防止将样式从一个 flex textArea 复制到另一个
【发布时间】:2009-11-03 18:39:15
【问题描述】:

如果您有两个具有不同样式(fontFamily、粗细、颜色等)的文本区域,并且您将文本从一个复制到另一个,它也会从原始文本区域复制样式。有什么巧妙的方法可以防止这种情况发生吗?

这是一个说明问题的代码示例。在顶部框中键入一些文本,在底部键入一些文本,然后将一些字符从顶部框中复制到底部。我没有使用 htmltext。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
  <mx:VBox width="100%" height="100%">
    <mx:TextArea id="source" width="100%" fontWeight="bold" fontSize="20" height="50" />
    <mx:TextArea id="dest" width="100%" height="50" /> 
  </mx:VBox>
</mx:Application>

【问题讨论】:

    标签: apache-flex flash actionscript-3 textarea


    【解决方案1】:

    这是一个非常肮脏的 hack 来完成它:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="absolute"
        >
    
        <mx:Script>
            <![CDATA[
    
                public function reformat():void
                {
                    var hold:String = two.text
                    two.text = ""
                    two.htmlText = hold
                }
    
    
            ]]>
        </mx:Script>
    
        <mx:VBox width="100%" height="100%" >
    
            <mx:Button click="bonk()" />
    
            <mx:TextArea fontWeight="bold" id="one" width="100%" height="100%" />
    
            <mx:TextArea fontWeight="normal" id="two" width="100%" height="100%" change="reformat()" />
    
        </mx:VBox>
    
    
    </mx:Application>
    

    【讨论】:

    • 这非常接近解决方案。这里唯一的缺点是 two.text 现在是空的,你必须使用 htmlText,有什么方法可以让 two.text 也填充文本?
    【解决方案2】:

    你能展示一个代码示例吗?

    我的第一个猜测是您正在设置第一个文本区域的 htmlText 属性,并且您的颜色和样式是通过 HTML 实现的。您是否使用副本复制 html 标签?您可能需要覆盖 texthtmlText 设置器并去除标签(或更改它们)。

    我什至不确定文本区域的复制/粘贴是否会复制其中的 HTML。不过似乎很有道理。

    【讨论】:

    • 不。我正在设置 text 属性,根本不使用 htmlText 。如果我使用的是 htmlText,那么我可能会看到问题正在发生。
    • 哇!你说得对。测试了代码。这太疯狂了。您仍然可以使用对“text”或“htmlText”设置器的覆盖来解决它。似乎它正在使用一些 HTML 格式。
    • 哈,很高兴知道我不只是疯了,谢谢你的确认:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    • 2011-05-28
    • 2012-09-27
    • 2018-11-04
    • 2021-11-26
    • 2015-04-26
    相关资源
    最近更新 更多