The web site for Flash ActionScript 3.0 game developers

 
         
   

Vertical Text (text rotation)

This was hard to find when googling, so I thought I'd post it here (also, kind of a tricky implementation for something pretty straight forward...).

Basically, all the below does is align text vertically. There are a bunch of lines which are commented out. Seems there are some inconsistencies in how fonts are implemented on various systems (mac, pc, etc). If you are trying this code and it does not work, try playing with the commented out lines.

Also, importantly, you need to import AND manually add the "linkage" for a font that you want to rotate. The basic steps (and explanation) for that are in Gary's book on page 306.

package
{
import flash.display.*;
import flash.text.*;

public class RotateText extends MovieClip
{

public function RotateText()
{
//common system font, not imported into library -- DOES NOT WORK
//var specialFormat:TextFormat = new TextFormat("Verdana",36,0x000000,true,false,false,null,null,TextFormatAlign.CENTER);

//common system font, not imported into library -- DOES NOT WORK
//var specialFormat:TextFormat = new TextFormat("Impact",36,0x000000,true,false,false,null,null,TextFormatAlign.CENTER);

//common system font, imported into library -- DOES NOT WORK
//var specialFormat:TextFormat = new TextFormat("Arial",36,0x000000,true,false,false,null,null,TextFormatAlign.CENTER);

//special font, imported into library -- WORKS!
//var specialFormat:TextFormat = new TextFormat("BigMummy",36,0x000000,true,false,false,null,null,TextFormatAlign.CENTER);

var specialFormat:TextFormat = new TextFormat("Verdana",24,0x000000);

var tf:TextField = new TextField;
tf.text = "THIS IS A TEST";
tf.autoSize = TextFieldAutoSize.LEFT;
tf.setTextFormat(specialFormat);
//tf.defaultTextFormat = specialFormat; //DOES NOT WORK! TEXT WILL NOT SHOW ON SCREEN!

/*Gary's comment:
The second one will set the default format, but will not change how it
looks if it has already been used.
*/

tf.x = 50;
tf.y = 5;
tf.embedFonts = true;
tf.rotation = 90;

addChild(tf);
trace("textfield on screen at " + tf.x +":"+ tf.y);

}

}
}



Copyright Gary Rosenzweig