忘记利用Html标签插入表情的痛苦吧,现在利用Adobe的TextLayout FrameWork可以很方便的插入表情,就象插入单个字符一样方便,而且插入的表情可以用鼠标选取。下面是利用官方范例稍加修改后的效果:
代码在这里:
package {
import flash.display.Sprite;
import flash.events.Event;
import flashx.textLayout.container.*;
import flashx.textLayout.elements.*;
import flashx.textLayout.events.StatusChangeEvent;
import flashx.textLayout.edit.SelectionManager;
public class myFace extends Sprite {
private var _textFlow:TextFlow;
public function myFace() {
_textFlow = new TextFlow();
_textFlow.fontSize=24;
var p:ParagraphElement = new ParagraphElement();
_textFlow.addChild(p);
var span:SpanElement = new SpanElement();
span.text="欢迎访问";
p.addChild(span);
// InlineGraphicElement has "auto" width/height so the size can't be calculated till the graphic is loaded
var inlineGraphic:InlineGraphicElement = new InlineGraphicElement();
inlineGraphic.source="http://labs.fmser.cn/myFace/smile1.swf";
p.addChild(inlineGraphic);
span= new SpanElement();
span.text="FMSer.cn!";
p.addChild(span);
inlineGraphic = new InlineGraphicElement();
inlineGraphic.source="http://labs.fmser.cn/myFace/smile2.swf";
p.addChild(inlineGraphic);
span= new SpanElement();
span.text="这是一个";
p.addChild(span);
inlineGraphic = new InlineGraphicElement();
inlineGraphic.source="http://labs.fmser.cn/myFace/smile3.swf";
p.addChild(inlineGraphic);
span= new SpanElement();
span.text="插入表情";
p.addChild(span);
inlineGraphic = new InlineGraphicElement();
inlineGraphic.source="http://labs.fmser.cn/myFace/smile4.swf";
p.addChild(inlineGraphic);
span= new SpanElement();
span.text="的例子。";
p.addChild(span);
// event sent when graphic is done loading
_textFlow.addEventListener(StatusChangeEvent.INLINE_GRAPHIC_STATUS_CHANGED,graphicStatusChangeEvent);
_textFlow.flowComposer.addController(new DisplayObjectContainerController(this,400,200));
// this call compose but the graphic hasn't been loaded from the source URL yet.
// The actualWidth and actualHeight are zero.
_textFlow.flowComposer.updateAllContainers();
_textFlow.interactionManager = new SelectionManager();
}
public function graphicStatusChangeEvent(evt:Event):void {
// the graphic has loaded (or failed to load) update the display
// actualWidth and actualHeight are computed from the graphic's height
_textFlow.flowComposer.updateAllContainers();
}
}
}
西部秋虫[