//正規表達式判斷字串中包含數字 GlobalData.numberRegExp=/\d/g;
override public function set text(value:String):void { if (value != null) { this.visible = false; //super.text = value; var numTf:TextFormat; var indexArr:Array = []; trace("override set text :" + value); switch (Main.languageType) { case LanguageType.en_US: super.text = value; break; case LanguageType.zh_TW: if (GlobalData.numberRegExp.test(String(value))&&value.length>0) { //若字串內包含數字(1~more) numTf = this.getTextFormat(); //copy default format numTf.font = GlobalData.font2.fontName; indexArr = searchCharCode(value).concat(); super.text = value; for (var j:int = 0; j < indexArr.length; j++) { this.setTextFormat(numTf, indexArr[j], (indexArr[j] + 1)); } }else { super.text = value; } break; } } else { trace("value == null"); } this.visible = true; return; } //搜尋字元 private static function searchCharCode(str:String):Array { var tempArr = []; for (var i:int = 0; i < str.length; i++) { if (str.charCodeAt(i) >= 46 && str.charCodeAt(i) <= 57) { tempArr.push(i); } } return tempArr; }
沒有留言:
張貼留言