Flex中通过selectable属性控制用户是否可以对TextArea中的文本进行选中的例子
By Minidxer | August 7, 2008
接下来的例子演示了Flex中如何通过selectable属性,控制用户是否可以对TextArea中的文本进行选中。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application name="TextArea_selectable_test"
- xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <mx:ApplicationControlBar dock="true">
- <mx:Form styleName="plain">
- <mx:FormItem label="selectable:">
- <mx:CheckBox id="checkBox"
- selected="true" />
- </mx:FormItem>
- </mx:Form>
- </mx:ApplicationControlBar>
- <mx:TextArea id="textArea"
- selectable="{checkBox.selected}"
- text="The quick brown fox jumped over the lazy dog." />
- </mx:Application>
下面是ActionScript的实现:
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <!-- http://blog.flexexamples.com/2008/08/06/toggling-whether-a-user-can-select-text-in-a-textarea-control-in-flex/ -->
- <mx:Application name="TextArea_selectable_test"
- xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <mx:Script>
- <![CDATA[
- private function checkBox_change(evt:Event):void {
- textArea.selectable = checkBox.selected;
- }
- ]]>
- </mx:Script>
- <mx:ApplicationControlBar dock="true">
- <mx:Form styleName="plain">
- <mx:FormItem label="selectable:">
- <mx:CheckBox id="checkBox"
- selected="true"
- change="checkBox_change(event);" />
- </mx:FormItem>
- </mx:Form>
- </mx:ApplicationControlBar>
- <mx:TextArea id="textArea"
- text="The quick brown fox jumped over the lazy dog." />
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
Flex |
No Comments » |
82 views
Tags: selectable, TextArea