首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

flex 兑现sql语句关键字高亮显示

2013-07-08 
flex 实现sql语句关键字高亮显示?xml version1.0 encodingutf-8?mx:Application xmlns:mxhttp:

flex 实现sql语句关键字高亮显示

<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"minWidth="955"minHeight="600" xmlns:local="*"><mx:Script><![CDATA[import mx.collections.ArrayCollection;import mx.controls.Alert;[Bindable]public var keyArray:ArrayCollection=new ArrayCollection(["AS", "SELECT", "FROM", "WHERE", "AND", "OR"]);]]></mx:Script><local:HighlightKeywordTextArea width="500" height="300" keyColor="red" keyArray="{keyArray}" text="select name as 姓名 from user_info where id='key'"></local:HighlightKeywordTextArea></mx:Application>



<?xml version="1.0" encoding="utf-8"?><mx:TextArea xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="textarea_creationCompleteHandler(event)"><mx:Script><![CDATA[import mx.collections.ArrayCollection;import mx.controls.Alert;import mx.controls.textClasses.TextRange;import mx.events.FlexEvent;[Bindable]public var keyArray:ArrayCollection;[Bindable]public var keyColor:String="red";private var tr:TextRange;private var crlf:String=String.fromCharCode(13);private var regEx:RegExp=new RegExp(crlf, "g");private function setKeyColor(num:int, key:String):void{var text:String=this.text.toUpperCase().replace(regEx, " ");var str:String=text.substr(num, text.length);var strArray:Array=str.split(" ");var keyIndex:int=strArray.indexOf(key);if (keyIndex != -1){if (keyIndex != 0){for (var i:int; i < keyIndex; i++){num+=(strArray[i] as String).length + 1;}}var length:int=key.length;tr=new TextRange(this, false, num, num + length);tr.color=keyColor;num+=(length + 1);if (num < text.length){setKeyColor(num, key);}}}private function addTextRange():void{try{tr=new TextRange(this);tr.color="black";tr.textDecoration="normal";tr.fontSize=20;for each (var key:String in keyArray){setKeyColor(0, key);}}catch (err:RangeError){}}private function textArea_change(evt:Event):void{addTextRange();}protected function textarea_creationCompleteHandler(event:FlexEvent):void{addTextRange();}]]></mx:Script></mx:TextArea>

热点排行