Apr 25

接下来的例子演示了Flex的TextArea控件中,如何利用htmlText属性和condenseWhite属性,将HTML的空格进行紧缩。

让我们先来看一下Demo(可以右键View Source或点击这里察看源代码


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="middle"
  5.         backgroundColor="white">
  6.  
  7.     <mx:String id="lorem" source="lorem.html" />
  8.  
  9.     <mx:ApplicationControlBar dock="true">
  10.         <mx:Form styleName="plain">
  11.             <mx:FormItem label="condenseWhite:">
  12.                 <mx:CheckBox id="checkBox" />
  13.             </mx:FormItem>
  14.         </mx:Form>
  15.     </mx:ApplicationControlBar>
  16.  
  17.     <mx:TextArea id="textArea"
  18.             htmlText="{lorem}"
  19.             condenseWhite="{checkBox.selected}"
  20.             width="100%"
  21.             height="100%" />
  22.  
  23. </mx:Application>
如果你想用ActionScript创建TextArea,那代码大致是下面这样:
Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="middle"
  5.         backgroundColor="white"
  6.         creationComplete="init();">
  7.  
  8.     <mx:Script>
  9.         <![CDATA[
  10.             import mx.controls.TextArea;
  11.  
  12.             private var textArea:TextArea;
  13.  
  14.             private function init():void {
  15.                 textArea = new TextArea();
  16.                 textArea.htmlText = lorem;
  17.                 textArea.condenseWhite = checkBox.selected;
  18.                 textArea.percentWidth = 100;
  19.                 textArea.percentHeight = 100;
  20.                 addChild(textArea);
  21.             }
  22.  
  23.             private function checkBox_change(evt:Event):void {
  24.                 var ch:CheckBox = evt.currentTarget as CheckBox;
  25.                 textArea.condenseWhite = ch.selected;
  26.             }
  27.         ]]>
  28.     </mx:Script>
  29.  
  30.     <mx:String id="lorem" source="lorem.html" />
  31.  
  32.     <mx:ApplicationControlBar dock="true">
  33.         <mx:Form styleName="plain">
  34.             <mx:FormItem label="condenseWhite:">
  35.                 <mx:CheckBox id="checkBox"
  36.                         change="checkBox_change(event);" />
  37.             </mx:FormItem>
  38.         </mx:Form>
  39.     </mx:ApplicationControlBar>
  40.  
  41. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:minidxer

written by Minidxer  |  tags: , , , ,

Related Post

One Response to “Flex的TextArea控件中如何利用htmlText属性以及condenseWhite属性紧缩HTML空格的例子”

Trackbacks

Leave a Reply