package { import flash.display.*; import flash.text.engine.*; [SWF(width="600", height="100")] public class FTEDemo14 extends Sprite { [Embed(source="assets/noreppachromus_small.jpg")] private var butterfly:Class; public function FTEDemo14() { super(); var str:String = 'Noreppa is a genus of neotropical ' + 'charaxine butterflies in the family ' + 'Nymphalidae, native to Colombia, Bolivia, ' + 'Venezuela, Peru and Argentina. It is a ' + 'monotypic genus. The single species is ' + 'Noreppa chromus (Guérin-Ménéville, 1844).'; var container1:Sprite = new Sprite(); container1.graphics.beginFill(0x00, 0.1); container1.graphics.drawRect(0, 0, 195, 100); addChild(container1); var container2:Sprite = new Sprite(); container2.graphics.beginFill(0x00, 0.1); container2.graphics.drawRect(0, 0, 195, 100); addChild(container2); container2.x = 205; var container3:Sprite = new Sprite(); container3.graphics.beginFill(0x00, 0.1); container3.graphics.drawRect(0, 0, 133, 100); addChild(container3); container3.x = 410; var block:TextBlock = new TextBlock(new TextElement(str, new ElementFormat(null, 18))); block.textJustifier = new SpaceJustifier("en", LineJustification.ALL_BUT_LAST, true); var line:TextLine = layoutBlock(block, null, container1); if(line) line = layoutBlock(block, line, container2); container3.addChild(new butterfly()); } // Returns the last line rendered out of the TextBlock private function layoutBlock(block:TextBlock, previousLine:TextLine, container:DisplayObjectContainer):TextLine { var line:TextLine = block.createTextLine(previousLine, container.width); var y:Number = 0; while(line) { container.addChild(line); y += line.ascent; line.y = y; y += line.descent; //If we reached the height boundary, return the last line that fit. if(y + line.height > container.height) return line; line = block.createTextLine(line, container.width); } return line; } } }