package { import flash.display.Sprite; import flash.text.engine.*; [SWF(width="200", height="180")] public class FTEDemo13 extends Sprite { public function FTEDemo13() { var e1:TextElement = new TextElement('"Breaking Bad has inspired me to learn more about chemistry."', new ElementFormat(null, 20)); var e2:TextElement = new TextElement('\n- Rainn Wilson', new ElementFormat(null, 20, 0xCC3300)); var block1:TextBlock = new TextBlock(new GroupElement(new [e1, e2], new ElementFormat())); var e3:TextElement = new TextElement('"\'Mad Men\' has inspired me to learn more about debauchery and self-loathing."', new ElementFormat(null, 20)); var e4:TextElement = new TextElement('\n- Rainn Wilson', new ElementFormat(null, 20, 0xCC3300)); var block2:TextBlock = new TextBlock(new GroupElement(new [e3, e4], new ElementFormat())); var blocks:Vector. = new [block1, block2]; var y:Number = 0; for(var i:int = 0; i < blocks.length; ++i) { y = layoutBlock(blocks[i], y); y += 5; } } // Returns the aggregate y after this layout operation private function layoutBlock(block:TextBlock, y:Number):Number { var line:TextLine = block.createTextLine(null, 185); line.x = 15; while(line) { addChild(line); y += line.ascent; line.y = y; y += line.descent; line = block.createTextLine(line, 200); } return y; } } }