package { import flash.display.*; import flash.events.*; import flash.geom.Rectangle; import flash.text.engine.*; import flash.utils.Dictionary; import flashx.textLayout.formats.BaselineOffset; [SWF(width="400", height="110")] public class FTEDemo6 extends Sprite { public function FTEDemo6() { var e1:TextElement = new TextElement('Outside the group. ', new ElementFormat( new FontDescription("Times", FontWeight.NORMAL, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 18)); var d2:EventDispatcher = new EventDispatcher(); d2.addEventListener(MouseEvent.MOUSE_OVER, function(e:Event):void{print("1: " + e.type);}); d2.addEventListener(MouseEvent.MOUSE_OUT, function(e:Event):void{print("1: " + e.type);}); var e2:TextElement = new TextElement('First group child. ', new ElementFormat( new FontDescription("Times", FontWeight.NORMAL, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 18, 0x44AA00), d2); var d3:EventDispatcher = new EventDispatcher(); d3.addEventListener(MouseEvent.MOUSE_OVER, function(e:Event):void{print("2: " + e.type);}); d3.addEventListener(MouseEvent.MOUSE_OUT, function(e:Event):void{print("2: " + e.type);}); var e3:TextElement = new TextElement('Second group child. ', new ElementFormat( new FontDescription("Times", FontWeight.NORMAL, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 18, 0xAA0044), d3); var e4:TextElement = new TextElement('Outside the group.', new ElementFormat( new FontDescription("Times", FontWeight.NORMAL, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 18)); var vec:Vector. = new Vector.(); vec.push(e2, e3); var groupDispatcher:EventDispatcher = new EventDispatcher(); groupDispatcher.addEventListener(MouseEvent.MOUSE_OVER, function(e:Event):void{print("group: " + e.type);}); groupDispatcher.addEventListener(MouseEvent.MOUSE_OUT, function(e:Event):void{print("group: " + e.type);}); var group:GroupElement = new GroupElement(vec, null, groupDispatcher); var vec2:Vector. = new Vector.(); vec2.push(e1, group, e4); var block:TextBlock = new TextBlock(new GroupElement(vec2)); var line:TextLine = block.createTextLine(null, 200); var _y:Number = 0; while(line) { addChild(line); _y += line.height; line.y = _y; line = block.createTextLine(line, 200); } addChild(lineHolder); lineHolder.x = 200; addEventListener(MouseEvent.MOUSE_DOWN, clearLines); } private function clearLines(event:MouseEvent):void { while(lineHolder.numChildren) lineHolder.removeChildAt(0); } private var lineHolder:Sprite = new Sprite(); private function print(str:String):void { while(lineHolder.numChildren > 6) lineHolder.removeChildAt(0); var block:TextBlock = new TextBlock( new TextElement(str, new ElementFormat( new FontDescription("Times", FontWeight.NORMAL, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 16) ) ); var line:TextLine = block.createTextLine(null, 200); while(line) { lineHolder.addChild(line); line = block.createTextLine(line, 200); } var child:DisplayObject; for(var i:int = 0; i < lineHolder.numChildren; i++) { child = lineHolder.getChildAt(i); child.y = (i+1) * child.height; } } [Embed(source="assets/Times New Roman.ttf", embedAsCFF="true", fontFamily="Times")] private var times:Class; } }