Chapter 17 Example 2

by actionscriptbible
♥0 | Line 32 | Modified 2009-06-28 03:55:40 | MIT License
play

ActionScript3 source code

/**
 * Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mu7Y
 */

package {
  import flash.display.Sprite;
  import flash.text.TextField;
  import flash.text.TextFieldAutoSize;
  
  public class ch17ex2 extends Sprite {
    protected const TEXT:String =  "Gaius Marius (157 BCE-January 13, 86 BCE)\
was a Roman general and politician";
    
    public function ch17ex2() {
      //A - manually sized, small
      var smalltf:TextField = new TextField();
      smalltf.border = true; //we'll turn on the border to see the size
      smalltf.width = 100;
      smalltf.height = 30;
      smalltf.text = TEXT;
      smalltf.y = 0; //appears on top
      addChild(smalltf); //not all text will fit
      
      //B - manually sized, big
      var bigtf:TextField = new TextField();
      bigtf.border = true;
      bigtf.width = 800;
      bigtf.height = 30;
      bigtf.text = TEXT;
      bigtf.y = 50; //appears in the middle
      addChild(bigtf); //all the text fits, with extra space 
      
      //C - autosizing
      var autotf:TextField = new TextField();
      autotf.border = true;
      autotf.width = autotf.height = 0; //let autosize grow the size from 0
      autotf.autoSize = TextFieldAutoSize.LEFT;
      autotf.text = TEXT;
      autotf.y = 100; //appears on bottom
      addChild(autotf); //all text fits perfectly
    }
  }
}