Packagecom.afcomponents.umap.styles
Classpublic class TextStyle
InheritanceTextStyle Inheritance Style

Specifies a text style for a TextField object. To use this object you should first create it's instance, define text style properties, and use applyTo() method to set the text style & content for the specified TextField object.


Example
Here is a quick usage example:
 import com.afcomponents.umap.styles.TextStyle;
 import flash.text.TextFieldAutoSize;
  
 // create new text style
 var style:TextStyle = new TextStyle();
 style.autoSize = TextFieldAutoSize.LEFT;
 style.textFormat.bold = true;
 style.textFormat.color = 0xFF0000;
  
 // create text field
 var textField:TextField = new TextField();
 textField.border = true;
 this.addChild(textField);
  
 // apply style & text to the text field
 style.applyTo(textField, "sample text");
 

You should see a text field with "sample text" written in red:

TextStyle example

See also

flash.text.TextField


Public Properties
 PropertyDefined by
  antiAliasType : String = "advanced"
The type of anti-aliasing used for this text field.
TextStyle
  autoSize : String = "none"
Controls automatic sizing and alignment of text fields.
TextStyle
  condenseWhite : Boolean = true
A Boolean value that specifies whether extra white space (spaces, line breaks, and so on) in a text field with HTML text should be removed.
TextStyle
  embedFonts : Boolean = false
Specifies whether to render by using embedded font outlines.
TextStyle
  gridFitType : String = "pixel"
The type of grid fitting used for this text field.
TextStyle
  html : Boolean = false
Indicates whether to render text as HTML.
TextStyle
  multiline : Boolean = false
Indicates whether the text field is a multiline text field.
TextStyle
  selectable : Boolean = false
A Boolean value that indicates whether the text field is selectable.
TextStyle
  sharpness : Number = 0
The sharpness of the glyph edges in this text field.
TextStyle
  styleSheet : StyleSheet = null
Specifies a flash.text.StyleSheet object that will be applied to the text field if html property is set to true.
TextStyle
  textFormat : TextFormat
Specifies a flash.text.TextFormat object that will be applied to the text field if html property is set to false.
TextStyle
  thickness : Number = 0
The thickness of the glyph edges in this text field.
TextStyle
  wordWrap : Boolean = false
A Boolean value that indicates whether the text field has word wrap.
TextStyle
Public Methods
 MethodDefined by
  
TextStyle(param:Object = null)
TextStyle contructor.
TextStyle
  
applyTo(textField:TextField, text:String = null):void
Applies current text style to a TextField object and sets it content if the text parameter is specified.
TextStyle
 Inherited
Creates a copy of the Style object.
Style
 Inherited
concat(param:Object):Style
Creates a clone of this Style, copies the properties from specified object and returns the new style.
Style
 Inherited
copy(object:Object):void
Copies all the properties from the specified object into the Style object.
Style
 Inherited
copyStyle(dest:Object, src:Object):void
[static] Copies all properties of one object into another.
Style
 Inherited
[static] Returns new Style object, from the source XML object.
Style
 Inherited
getXMLFromStyle(style:Style, name:String = ""):XML
[static] Returns an XML object that represents all the style's properties.
Style
 Inherited
toString():String
Returns a String that represents all the style's properties.
Style
 Inherited
toXML(afcTags:Boolean = false):XML
Abstract function.
Style
Property detail
antiAliasTypeproperty
public var antiAliasType:String = "advanced"

The type of anti-aliasing used for this text field. Use flash.text.AntiAliasType constants for this property. You can control this setting only if the font is embedded (with the embedFonts property set to true). The default setting is flash.text.AntiAliasType.ADVANCED.

To set values for this property, use the following string values:

String valueDescription
flash.text.AntiAliasType.NORMALApplies the regular text anti-aliasing. This matches the type of anti-aliasing that Flash Player 7 and earlier versions used.
flash.text.AntiAliasType.ADVANCEDApplies advanced anti-aliasing, which makes text more legible. (This feature became available in Flash Player 8.) Advanced anti-aliasing allows for high-quality rendering of font faces at small sizes. It is best used with applications that have a lot of small text. Advanced anti-aliasing is not recommended for fonts that are larger than 48 points.

The default value is flash.text.AntiAliasType.ADVANCED.

See also

gridFitType
sharpness
flash.text.AntiAliasType
autoSizeproperty 
public var autoSize:String = "none"

Controls automatic sizing and alignment of text fields.

Acceptable values for the TextFieldAutoSize constants:

String valueDescription
TextFieldAutoSize.NONENo resizing occurs. (the default)
TextFieldAutoSize.LEFTThe text is treated as left-justified text, meaning that the left margin of the text field remains fixed and any resizing of a single line of the text field is on the right margin. If the text includes a line break (for example, "\n" or "\r"), the bottom is also resized to fit the next line of text. If wordWrap is also set to true, only the bottom of the text field is resized and the right side remains fixed.
TextFieldAutoSize.RIGHTThe text is treated as right-justified text, meaning that the right margin of the text field remains fixed and any resizing of a single line of the text field is on the left margin. If the text includes a line break (for example, "\n" or "\r"), the bottom is also resized to fit the next line of text. If wordWrap is also set to true, only the bottom of the text field is resized and the left side remains fixed.
TextFieldAutoSize.CENTERThe text is treated as center-justified text, meaning that any resizing of a single line of the text field is equally distributed to both the right and left margins. If the text includes a line break (for example, "\n" or "\r"), the bottom is also resized to fit the next line of text. If wordWrap is also set to true, only the bottom of the text field is resized and the left and right sides remain fixed.

The default value is TextFieldAutoSize.NONE.

See also

flash.text.TextFieldAutoSize
condenseWhiteproperty 
public var condenseWhite:Boolean = true

A Boolean value that specifies whether extra white space (spaces, line breaks, and so on) in a text field with HTML text should be removed. The condenseWhite property only work with html property set to true. If html property is set to false, condenseWhite is ignored.

If you set condenseWhite to true, you must use standard HTML commands such as <BR&ht; and <P&ht; to place line breaks in the text field.

The default value is true.


Example
The following shows the difference between setting the condenseWhite setting to false and setting it to true:
  import flash.text.TextField;
  import com.afcomponents.umap.styles.TextStyle;
   
  // create 2 text fields
  var tf1:TextField = createTextField(0, 0, 200, 50);
  var tf2:TextField = createTextField(0, 120, 200, 50);
   
  // create & apply text style
  var style:TextStyle = new TextStyle();
  style.html = true;
  style.condenseWhite = false;
  style.applyTo(tf1, "keep    on\n\ttruckin'");
  style.condenseWhite = true;
  style.applyTo(tf2, "keep    on\n\ttruckin'");
   
  function createTextField(x:Number, y:Number, width:Number, height:Number):TextField 
  {
   var result:TextField = new TextField();
   result.x = x;
   result.y = y;
   result.width = width;
   result.height = height;
   result.border = true;
   addChild(result);
   return result;
  }

embedFontsproperty 
public var embedFonts:Boolean = false

Specifies whether to render by using embedded font outlines. If false, Flash Player renders the text field by using device fonts.

If you set the embedFonts property to true for a text field, you must specify a font for that text by using the font property of a TextFormat object applied to the text field. If the specified font is not embedded in the SWF file, the text is not displayed.

The default value is false.


Example
Here is an example of rendering text with device and embedded font outlines:
  import flash.text.TextField;
  import com.afcomponents.umap.styles.TextStyle;
   
  // create 2 text fields
  var tf1:TextField = createTextField(0, 0, 200, 50);
  var tf2:TextField = createTextField(0, 120, 200, 50);
   
  // create & apply text style
  // don't forget to create a new font in your library based on "_sans" face
  var style:TextStyle = new TextStyle();
  style.textFormat.font = "_sans";
  style.textFormat.size = 14;
  style.applyTo(tf1, "(device fonts) sample text");
  style.embedFonts = true;
  style.applyTo(tf2, "(embedded fonts) sample text");
   
  function createTextField(x:Number, y:Number, width:Number, height:Number):TextField 
  {
   var result:TextField = new TextField();
   result.x = x;
   result.y = y;
   result.width = width;
   result.height = height;
   result.border = true;
   addChild(result);
   return result;
  }

gridFitTypeproperty 
public var gridFitType:String = "pixel"

The type of grid fitting used for this text field. This property applies only if the flash.text.AntiAliasType property of the text field is set to flash.text.AntiAliasType.ADVANCED.

The type of grid fitting used determines whether Flash Player forces strong horizontal and vertical lines to fit to a pixel or subpixel grid, or not at all.

For the flash.text.GridFitType property, you can use the following string values:

String valueDescription
flash.text.GridFitType.NONESpecifies no grid fitting. Horizontal and vertical lines in the glyphs are not forced to the pixel grid. This setting is usually good for animation or for large font sizes.
flash.text.GridFitType.PIXELSpecifies that strong horizontal and vertical lines are fit to the pixel grid. This setting works only for left-aligned text fields. To use this setting, the flash.dispaly.AntiAliasType property of the text field must be set to flash.text.AntiAliasType.ADVANCED. This setting generally provides the best legibility for left-aligned text.
flash.text.GridFitType.SUBPIXELSpecifies that strong horizontal and vertical lines are fit to the subpixel grid on an LCD monitor. To use this setting, the flash.text.AntiAliasType property of the text field must be set to flash.text.AntiAliasType.ADVANCED. The flash.text.GridFitType.SUBPIXEL setting is often good for right-aligned or centered dynamic text, and it is sometimes a useful trade-off for animation versus text quality.

The default value is GridFitType.PIXEL.

See also

htmlproperty 
public var html:Boolean = false

Indicates whether to render text as HTML. For the list of supported tags please consult Flash CS3 Help system.

For convinience purposes, if html property is set to true the text passed to applyTo() method will be enclosed by tags.

The default value is false.

See also

flash.text.TextField

Example
Here is a quick usage example:
  import flash.text.TextField;
  import flash.text.TextFieldAutoSize;
  import com.afcomponents.umap.styles.TextStyle;
   
  // create text field
  var textField:TextField = new TextField();
  this.addChild(textField);
   
  // create & apply style
  var style:TextStyle = new TextStyle();
  style.autoSize = TextFieldAutoSize.LEFT;
  style.html = true;
   
  style.applyTo(textField, "this is HTML text");

multilineproperty 
public var multiline:Boolean = false

Indicates whether the text field is a multiline text field. If the value is true, the text field is multiline; if the value is false, the text field is a single-line text field.

The default value is false.

selectableproperty 
public var selectable:Boolean = false

A Boolean value that indicates whether the text field is selectable. The value true indicates that the text is selectable. The selectable property controls whether a text field is selectable, not whether a text field is editable. A dynamic text field can be selectable even if it is not editable. If a dynamic text field is not selectable, the user cannot select its text.

If selectable is set to false, the text in the text field does not respond to selection commands from the mouse or keyboard, and the text cannot be copied with the Copy command. If selectable is set to true, the text in the text field can be selected with the mouse or keyboard, and the text can be copied with the Copy command. You can select text this way even if the text field is a dynamic text field instead of an input text field.

The default value is false.

sharpnessproperty 
public var sharpness:Number = 0

The sharpness of the glyph edges in this text field. This property applies only if the flash.text.AntiAliasType property of the text field is set to flash.text.AntiAliasType.ADVANCED. The range for sharpness is a number from -400 to 400. If you attempt to set sharpness to a value outside that range, Flash sets the property to the nearest value in the range (either -400 or 400).

The default value is false.

See also

styleSheetproperty 
public var styleSheet:StyleSheet = null

Specifies a flash.text.StyleSheet object that will be applied to the text field if html property is set to true.

To define a style for all the text, please use "html" as the style name.


Example
Here is a quick example:
  import flash.text.TextField;
  import flash.text.TextFieldAutoSize;
  import flash.text.StyleSheet;
  import com.afcomponents.umap.styles.TextStyle;
   
  // create text field
  var textField:TextField = new TextField();
  this.addChild(textField);
   
  // create a StyleSheet object
  var css:StyleSheet = new StyleSheet();
  css.setStyle("style1", {fontSize:16, fontFamily:"Arial", fontWeight:"bold"});
  css.setStyle("style2", {fontSize:14, fontFamily:"Courier", fontStyle:"italic"});
   
  // create & apply style
  var style:TextStyle = new TextStyle();
  style.multiline = true;
  style.autoSize = TextFieldAutoSize.LEFT;
  style.html = true;
  style.styleSheet = css;
   
  style.applyTo(textField, "This is HTML textwith a style sheet formating");

textFormatproperty 
public var textFormat:TextFormat

Specifies a flash.text.TextFormat object that will be applied to the text field if html property is set to false.

The default value is font: "_sans", size: 12.


Example
Here is a quick example:
  import flash.text.TextField;
  import flash.text.TextFieldAutoSize;
  import flash.text.TextFormat;
  import com.afcomponents.umap.styles.TextStyle;
   
  // create text field
  var textField:TextField = new TextField();
  this.addChild(textField);
   
  // create a TextFormat object
  var format:TextFormat = new TextFormat();
  format.bold = true;
  format.underline = true;
  format.size = 20;
   
  // create & apply style
  var style:TextStyle = new TextStyle();
  style.autoSize = TextFieldAutoSize.LEFT;
  style.textFormat = format;
   
  style.applyTo(textField, "This text is bold & underlined");

thicknessproperty 
public var thickness:Number = 0

The thickness of the glyph edges in this text field. This property applies only when flash.text.AntiAliasType is set to flash.text.AntiAliasType.ADVANCED.

The range for thickness is a number from -200 to 200. If you attempt to set thickness to a value outside that range, the property is set to the nearest value in the range (either -200 or 200).

The default value is 0.

See also

wordWrapproperty 
public var wordWrap:Boolean = false

A Boolean value that indicates whether the text field has word wrap. If the value of wordWrap is true, the text field has word wrap; if the value is false, the text field does not have word wrap. The default value is false.

The default value is false.

Constructor detail
TextStyle()constructor
public function TextStyle(param:Object = null)

TextStyle contructor.

Creates new TextStyle object with the default parameters. Properties defined in param object will override the default values. Please use applyTo() method to set the text style for the specified TextField object.

Parameters
param:Object (default = null) — Object that holds all the properites of a style you wish to override upon its creation.

See also

applyTo()
flash.text.TextField
Method detail
applyTo()method
public function applyTo(textField:TextField, text:String = null):void

Applies current text style to a TextField object and sets it content if the text parameter is specified.

Parameters
textField:TextField — Reference to a TextField object.
 
text:String (default = null) — Optional text string to set TextField's content.