Apr 25
接下来的例子演示了Flex的TextArea控件中,如何利用htmlText属性和condenseWhite属性,将HTML的空格进行紧缩。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <mx:String id="lorem" source="lorem.html" />
- <mx:ApplicationControlBar dock="true">
- <mx:Form styleName="plain">
- <mx:FormItem label="condenseWhite:">
- <mx:CheckBox id="checkBox" />
- </mx:FormItem>
- </mx:Form>
- </mx:ApplicationControlBar>
- <mx:TextArea id="textArea"
- htmlText="{lorem}"
- condenseWhite="{checkBox.selected}"
- width="100%"
- height="100%" />
- </mx:Application>
如果你想用ActionScript创建TextArea,那代码大致是下面这样:
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white"
- creationComplete="init();">
- <mx:Script>
- <![CDATA[
- import mx.controls.TextArea;
- private var textArea:TextArea;
- private function init():void {
- textArea = new TextArea();
- textArea.htmlText = lorem;
- textArea.condenseWhite = checkBox.selected;
- textArea.percentWidth = 100;
- textArea.percentHeight = 100;
- addChild(textArea);
- }
- private function checkBox_change(evt:Event):void {
- var ch:CheckBox = evt.currentTarget as CheckBox;
- textArea.condenseWhite = ch.selected;
- }
- ]]>
- </mx:Script>
- <mx:String id="lorem" source="lorem.html" />
- <mx:ApplicationControlBar dock="true">
- <mx:Form styleName="plain">
- <mx:FormItem label="condenseWhite:">
- <mx:CheckBox id="checkBox"
- change="checkBox_change(event);" />
- </mx:FormItem>
- </mx:Form>
- </mx:ApplicationControlBar>
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:minidxer
