1、
package module
{
import mx.controls.TextArea;
import mx.events.FlexEvent;
//mx.controls.TextArea 组件需要将焦点聚在它的身上来显示文本的选择
public class TextAreaDemo extends TextArea
{
public function TextAreaDemo()
{
//TODO: implement function
super();
this.addEventListener(FlexEvent.CREATION_COMPLETE,createComp);
}
public function createComp(event:FlexEvent):void
{
this.textField.alwaysShowSelection = true;
}
}
}
2、
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:cookbook="module.*" width="400" height="300">
<mx:Script>
<![CDATA[
[Bindable]
private var textInfo:String = "Aenean quis nunc id purus pharetra haretra. " +
"Cras a felis sit amet ipsum ornare luctus. Nullam scelerisque"
+" placerat velit. Pellentesque ut asdfasfsdfsdfasf sadd " +
"ddd aaa ddd arcu congue risus facilisis pellentesque." +
" Duis in enim. Mauris egetest. Quisque tortor.";
private function showSelectedText():void
{
var index:int = area.text.indexOf(inputValue.text);
area.verticalScrollPosition = 0;
if(index != -1)
{
area.setSelection(index,index+inputValue.text.length);
}
}
]]>
</mx:Script>
<mx:TextInput id="inputValue" change="showSelectedText()"/>
<cookbook:TextAreaDemo y="20" editable="false" id="area" width="200" height="100" text="{textInfo}"/>
</mx:Canvas>