package { import flash.display.Graphics; import flash.display.Sprite; import flash.events.EventDispatcher; import flash.events.MouseEvent; import flash.text.engine.*; [SWF(width="190", height="40")] public class SimpleDemo3 extends Sprite { public function SimpleDemo3() { super(); addChild(lineHolder); lineHolder.x = 100; var dispatcher:EventDispatcher = new EventDispatcher(); dispatcher.addEventListener(MouseEvent.MOUSE_MOVE, onMouseEvent); dispatcher.addEventListener(MouseEvent.MOUSE_OUT, onMouseEvent); dispatcher.addEventListener(MouseEvent.MOUSE_OVER, onMouseEvent); dispatcher.addEventListener(MouseEvent.MOUSE_DOWN, onMouseEvent); dispatcher.addEventListener(MouseEvent.MOUSE_UP, onMouseEvent); dispatcher.addEventListener(MouseEvent.CLICK, onMouseEvent); var block:TextBlock = new TextBlock(new TextElement('The quick brown fox...', new ElementFormat( new FontDescription("Times", FontWeight.NORMAL, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 18), dispatcher)); var line:TextLine = block.createTextLine(null, 100); var _y:Number = 0; while(line) { addChild(line); _y += line.height; line.y = _y; line = block.createTextLine(line, 100); } } private function onMouseEvent(event:MouseEvent):void { var target:TextLine = TextLine(event.target); renderNotification(event.type); } private var lineHolder:Sprite = new Sprite(); private function renderNotification(text:String):void { while(lineHolder.numChildren) lineHolder.removeChildAt(0); var block:TextBlock = new TextBlock( new TextElement(text, new ElementFormat( new FontDescription("Times", FontWeight.NORMAL, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 18) ) ); var line:TextLine = block.createTextLine(null, 200); while(line) { lineHolder.addChild(line); line.y = line.height; line = block.createTextLine(line, 200); } } [Embed(source="assets/Times New Roman.ttf", embedAsCFF="true", fontFamily="Times")] private var times:Class; } }