TextField嵌入表情图标,实现图文混排
主要代码是
/**
* 定位到表情符
*/
public function posSmileWord(){
clearSM();
var pattern:RegExp = //[sm/d/]/g;
var resultArray:Array = text.match(pattern);
if(resultArray!=null){
var sta:int=0;
for each(var s:String in resultArray ){
sta = bulidSmile(s,sta);
}
}else{
trace("==没有匹配的表情符");
}
}
private function bulidSmile(str:String,staIndex:int):int{
var startNum:Number = this.text.indexOf(str,staIndex);
var r = this.TargetField.getCharBoundaries(startNum);
if(r==null) return startNum+1;
if(this.targetField.getLineIndexOfChar(startNum)>(this.targetField.bottomScrollV-1)) return this.text.length;
//todo:将文字的表情符进行隐藏
//定位表情位置
var newSm:Smile = new Smile(str);
this.smilesArray.push(newSm);
newSm.x = r.x;
newSm.y= r.y-(this.targetField.scrollV-1)*this.targetField.getLineMetrics(0).height;
this.addChild(newSm);
return startNum+1;
}