Arranging story elements on the page

The StoryLayout class formats and lays out the headline, subtitle, and main text fields into a newspaper-style arrangement. The displayText() method initially creates and places the various fields.

public function displayText():void
{
    headlineTxt = new HeadlineTextField(h1Format);
    headlineTxt.wordWrap = true;
    this.addChild(headlineTxt);
    headlineTxt.width = 600;
    headlineTxt.height = 100;
    headlineTxt.fitText(this.headline, 1, true);
    
    subtitleTxt = new HeadlineTextField(h2Format);
    subtitleTxt.wordWrap = true;
    subtitleTxt.y = headlineTxt.y + headlineTxt.height;
    this.addChild(subtitleTxt);            
    subtitleTxt.width = 600;
    subtitleTxt.height = 100;
    subtitleTxt.fitText(this.subtitle, 1, false);
    
    storyTxt = new MultiColumnTextField(2, 10, 600, 200);
    storyTxt.y = subtitleTxt.y + subtitleTxt.height + 4;
    this.addChild(storyTxt);
    storyTxt.styleSheet = this.sheet;
    storyTxt.htmlText = loremIpsum;
}

Each field is simply placed below the previous field by setting its y property equal to the y property of the previous field plus the height of the previous field. This dynamic placement calculation is needed because HeadlineTextField objects and MultiColumnTextField objects can change their height to fit their contents.


Flash CS3