View comments | RSS feed

StyleSheet (TextField.StyleSheet)


Object
    |
    +-TextField.StyleSheet

public class StyleSheet
extends Object

The StyleSheet class lets you create a StyleSheet object that contains text formatting rules for font size, color, and other styles. You can then apply styles defined by a style sheet to a TextField object that contains HTML- or XML-formatted text. The text in the TextField object is automatically formatted according to the tag styles defined by the StyleSheet object. You can use text styles to define new formatting tags, redefine built-in HTML tags, or create style classes that you can apply to certain HTML tags.

To apply styles to a TextField object, assign the StyleSheet object to a TextField object's styleSheet property.

Flash Player supports a subset of properties in the original CSS1 specification (www.w3.org/TR/REC-CSS1). The following table shows the supported Cascading Style Sheet (CSS) properties and values, as well as their corresponding ActionScript property names. (Each ActionScript property name is derived from the corresponding CSS property name; if the name contains a hyphen, the hyphen is omitted and the subsequent character is capitalized.)

CSS property

ActionScript property

Usage and supported values

color

color

Only hexadecimal color values are supported. Named colors (such as blue) are not supported. Colors are written in the following format: #FF0000.

display

display

Supported values are inline, block, and none.

font-family

fontFamily

A comma-separated list of fonts to use, in descending order of desirability. Any font family name can be used. If you specify a generic font name, it is converted to an appropriate device font. The following font conversions are available: mono is converted to _typewriter, sans-serif is converted to _sans, and serif is converted to _serif.

font-size

fontSize

Only the numeric part of the value is used. Units (px, pt) are not parsed; pixels and points are equivalent.

font-style

fontStyle

Recognized values are normal and italic.

font-weight

fontWeight

Recognized values are normal and bold.

kerning

kerning

Recognized values are true and false. Kerning is supported for embedded fonts only. Certain fonts, such as Courier New, do not support kerning. The kerning property is only supported in SWF files created in Windows, not in SWF files created on the Macintosh. However, these SWF files can be played in non-Windows versions of Flash Player and the kerning still applies.

letter-spacing

letterSpacing

The amount of space that is uniformly distributed between characters. The value specifies the number of pixels that are added to the advance after each character. A negative value condenses the space between characters. Only the numeric part of the value is used. Units (px, pt) are not parsed; pixels and points are equivalent.

margin-left

marginLeft

Only the numeric part of the value is used. Units (px, pt) are not parsed; pixels and points are equivalent.

margin-right

marginRight

Only the numeric part of the value is used. Units (px, pt) are not parsed; pixels and points are equivalent.

text-align

textAlign

Recognized values are left, center, right, and justify.

text-decoration

textDecoration

Recognized values are none and underline.

text-indent

textIndent

Only the numeric part of the value is used. Units (px, pt) are not parsed; pixels and points are equivalent.

Availability: ActionScript 1.0; Flash Player 7

Property summary

Properties inherited from class Object

constructor, __proto__, prototype, __resolve


Event summary

Event

Description

onLoad = function(success:Boolean) {}

Invoked when a load() operation has completed.

Constructor summary

Signature

Description

StyleSheet()

Creates a StyleSheet object.

Method summary

Modifiers

Signature

Description

 

clear() : Void

Removes all styles from the specified StyleSheet object.

 

getStyle(name:String) : Object

Returns a copy of the style object associated with the specified style (name).

 

getStyleNames() : Array

Returns an array that contains the names (as strings) of all of the styles registered in this style sheet.

 

load(url:String) : Boolean

Starts loading the CSS file into the StyleSheet.

 

parseCSS(cssText:String) : Boolean

Parses the CSS in cssText and loads the StyleSheet with it.

 

setStyle(name:String, style:Object) : Void

Adds a new style with the specified name to the StyleSheet object.

 

transform(style:Object) : TextFormat

Extends the CSS parsing capability.

Methods inherited from class Object

addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch



Version 8

Comments


CheloXL said on Sep 30, 2005 at 10:56 AM :
fontFamily is a property of what actionscript class?
swartz1999 said on Oct 3, 2005 at 11:03 AM :
CheloXL, fontFamily the name one of the properties of the style object that you pass to the setStyle() method and that is returned by the getStyle() method. This is also true for all of the ActionScript properties listed in the table at the top of this page.
astgtciv said on Apr 8, 2006 at 7:13 PM :
Addendum to save people time: "letterSpacing" was introduced in Flash 8, it will not work in previous versions.
No screen name said on Jun 8, 2006 at 10:46 PM :
'leading' is not documented as style property but working
richardlmk said on Jul 11, 2006 at 9:08 AM :
When using an external stylesheet, you cannot have tabs between the style property, the colon and the style value. e.g.

.styleName { font-family : Arial; } // ok
.styleName { font-family : Arial; } // does not work
swartz1999 said on Aug 1, 2006 at 4:51 PM :
Thanks for your comment regarding leading. We are looking into this, and I will post a comment as soon as we have information.
swartz1999 said on Aug 1, 2006 at 4:53 PM :
Yes, richardlmk, this is a limitation. You cannot have tabs between the style property, the colon, and the style value.
No screen name said on Sep 25, 2006 at 4:33 PM :
I can't seem to get textTransform:uppercase to work. Is it unsupported?
3Dgregory said on Jan 19, 2007 at 3:38 PM :
What is the difference betwee display: inline, block, and none?
jakkub said on Jan 31, 2007 at 1:03 AM :
textAlign also does not work when published for player 7.
_Iv said on Feb 1, 2007 at 7:28 PM :
Quote: The following font conversions are available: mono is converted to _typewriter, sans-serif is converted to _sans, and serif is converted to _serif.

but:

import TextField.StyleSheet;
var test_css = new StyleSheet();
var success = test_css.parseCSS
(".sans {font-family:sans} .sans_serif {font-family:sans-serif} .mono {font-family:mono}");
trace("success: "+success); // success: true
//
trace("sans: "+test_css._styles[".sans"].font); // sans: sans
trace("sans_serif: "+test_css._styles[".sans_serif"].font); // sans_serif: _sans
trace("mono: "+test_css._styles[".mono"].font); // mono: _typewriter

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002714.html