<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
applicationComplete="initApp();" xmlns:components="com.components.*" minWidth="540" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.managers.ToolTipManager;
import mx.collections.ArrayCollection;
import mx.events.*;
import mx.controls.*;
import com.kingnare.regex.HighlightMultiBlock;
private var stylesEvent:IEventDispatcher;
private var myMenu:Menu;
private var lightArray:Array = [];
private var updateTimer:Timer;
private var flags:String;
private var autoUpdate:Boolean;
private function initApp():void
{
ToolTipManager.showDelay = 0;
myText.htmlText = "<font size='26' color='#00FF00'>TextField</font>类用于创建显示对象以显示和输入文本。 SWF 文件中的所有动态文本字段和输入文本字段都是 TextField 类的实例。 可以在属性检查器中为文本字段指定实例名称,并且可以在 <font size='30' color='#0066FF'>ActionScript</font> 中使用 TextField 类的方法和属性对文本字段进行操作。 TextField 实例名称显示在影片浏览器中以及“动作”面板的<font size='16' color='#FF6600'>“插入目标路径”</font>对话框中。<br/>" +
"若要动态创建文本字段,请使用 TextField() 构造函数。<br/>" +
"TextField 类的方法允许您设置、选择并操作在创作过程中或运行时创建的动态或输入文本字段中的文本。<br/><br/><br/>" +
"The<font size='26' color='#00FF00'>TextField</font> class is used to create display objects for text display and input. All dynamic and input text fields in a SWF file are instances of the TextField class. You can use the TextField class to perform low-level text rendering. However, in Flex, you typically use the <font size='20' color='#00FFFF'>Label, Text, TextArea, and TextInput</font> controls to process text.<br/>" +
" To create a text field dynamically, use the TextField() constructor.<br/>" +
"The methods of the TextField class let you set, select, and manipulate text in a dynamic or input text field that you create during authoring or at runtime.";
flags = "ig";
regexInput.text = "TextField";
autoUpdate = true;
myText.drawType = HighlightMultiBlock.TYPE_RECT;
myText.addEventListener(ScrollEvent.SCROLL, scrollEvent);
myText.addEventListener(Event.CHANGE, changeEvent);
myText.addEventListener(ResizeEvent.RESIZE, resizeEvent);
myText.addEventListener(MoveEvent.MOVE, moveEvent);
updateTimer = new Timer(5, 1);
updateTimer.addEventListener(TimerEvent.TIMER, validate, false, 0, true);
startLoadStyle();
}
private function startLoadStyle():void
{
panel.title = "HighLightClass Test"+" (Loading style...)";
stylesEvent = StyleManager.loadStyleDeclarations("style/style.swf");
stylesEvent.addEventListener(StyleEvent.ERROR, styleLoadError);
stylesEvent.addEventListener(StyleEvent.PROGRESS, styleLoadProgress);
stylesEvent.addEventListener(StyleEvent.COMPLETE, styleLoadComplete);
}
private function styleLoadError(event:StyleEvent):void
{
panel.title = "HighLightClass Test";
}
private function styleLoadProgress(event:StyleEvent):void
{
panel.title = "HighLightClass Test"+" (Loading style..."+Math.floor(event.bytesLoaded/event.bytesTotal*100)+"%)";
}
private function styleLoadComplete(event:StyleEvent):void
{
panel.title = "HighLightClass Test";
}
private function showBlock():void
{
myText.clearBlock();
var myPattern:RegExp = new RegExp(regexInput.text, flags);
var str:String = myText.text;
var result:Object = myPattern.exec(str);
if(flags.indexOf("g") != -1)
{
while (result != null)
{
myText.showBlock(result.index, result[0]);
result = myPattern.exec(str);
}
}
else
{
if(result != null)
{
myText.showBlock(result.index, result[0]);
}
}
}
private function validate(event:TimerEvent):void
{
if(autoUpdate)
{
showBlock();
}
}
private function scrollEvent(event:ScrollEvent):void
{
updateBlock();
}
private function changeEvent(event:Event):void
{
updateBlock();
}
private function resizeEvent(event:ResizeEvent):void
{
updateBlock();
}
private function moveEvent(event:MoveEvent):void
{
updateBlock();
}
private function updateBlock():void
{
updateTimer.reset();
updateTimer.start();
}
private function clearBlock():void
{
myText.clearBlock();
}
private function setI():void
{
if(ichk.selected)
{
if(flags.indexOf("i") == -1)
{
flags += "i";
}
}
else
{
if(flags.indexOf("i") != -1)
{
flags = flags.replace(/i/g, "");
}
}
updateBlock();
}
private function setG():void
{
if(gchk.selected)
{
if(flags.indexOf("g") == -1)
{
flags += "g";
}
}
else
{
if(flags.indexOf("g") != -1)
{
flags = flags.replace(/g/g, "");
}
}
updateBlock();
}
private function setAutoUpdate():void
{
autoUpdate = autochk.selected;
}
private function changeDrawType(event:Event):void
{
var rbg:RadioButtonGroup = event.target as RadioButtonGroup;
if(rbg != null)
{
switch(rbg.selection)
{
case rectRB:
myText.drawType = HighlightMultiBlock.TYPE_RECT;
break;
case underlineRB:
myText.drawType = HighlightMultiBlock.TYPE_UNDERLINE;
break;
default:
}
updateBlock();
}
}
]]>
</mx:Script>
<mx:Panel layout="absolute" title="HighLightClass Test" id="panel"
left="10" right="10" top="10" bottom="10">
<components:BlockTextArea id="myText" parentApp="{panel}"
borderStyle="solid"
left="10" right="10" top="71" bottom="10"
focusAlpha="0" fontSize="12"/>
<mx:Button id="goBtn"
label="Go"
top="10" width="60"
click="showBlock();" right="78"/>
<mx:Button id="clearBtn"
label="Clear"
top="10" width="60"
click="clearBlock();" right="10"/>
<mx:TextInput id="regexInput"
borderStyle="solid"
left="10" right="146" top="10"
fontSize="12" fontFamily="Arial"
focusAlpha="0"/>
<mx:RadioButtonGroup id="radiogroup1"/>
<mx:CheckBox x="10" y="41" label="i" id="ichk" selected="true" click="setI();"/>
<mx:CheckBox x="46" y="41" label="g" id="gchk" selected="true" click="setG();"/>
<mx:CheckBox y="41" label="auto update" id="autochk" selected="true" click="setAutoUpdate();" right="146"/>
<mx:RadioButtonGroup id="drawTypeGroup" change="changeDrawType(event);"/>
<mx:RadioButton y="41" label="Rectangle" groupName="drawTypeGroup" id="rectRB" right="335" selected="true"/>
<mx:RadioButton y="41" label="Underline" groupName="drawTypeGroup" id="underlineRB" right="247"/>
</mx:Panel>
</mx:Application>