Loading External CSS StyleSheets in Flash9 / AS3 / CS3
External CSS stylesheets can be used with flash AS3. This is possible with the StyleSheet class in AS3 and controls such as TextField have a property for the stylesheet.
AS2
var styles:TextField.StyleSheet = new TextField.StyleSheet(); styles.onLoad = function(success:Boolean):Void { if (success) { // display style names. trace(this.getStyleNames()); } else { trace("Error loading CSS file."); } }; styles.load("styles.css");
OR apply to a StyleSheet object that can be used for many controls
AS3
package { import flash.display.Sprite; import flash.events.Event; import flash.net.URLLoader; import flash.net.URLRequest; import flash.text.StyleSheet; import flash.text.TextField; import flash.text.TextFieldAutoSize; public class CSSFormattingExample extends Sprite { var loader:URLLoader; var field:TextField; var exampleText:String = "<h1>This is a headline</h1> " + "This is a line of text. <span class=\"bluetext\">" + "This line of text is colored blue.</span>"; public function CSSFormattingExample():void { field = new TextField(); field.width = 300; field.autoSize = TextFieldAutoSize.LEFT; field.wordWrap = true; addChild(field); var req:URLRequest = new URLRequest("example.css"); loader = new URLLoader(); loader.addEventListener(Event.COMPLETE, onCSSFileLoaded); loader.load(req); } public function onCSSFileLoaded(event:Event):void { var sheet:StyleSheet = new StyleSheet(); sheet.parseCSS(loader.data); field.styleSheet = sheet; field.htmlText = exampleText; } } }
[SOURCE]
Flash is limited in CSS support and only supports CSS1 properties and a minimal amount for formatting.
Supported CSS properties
Flash Player supports a subset of properties in the original CSS1 specification (www.w3.org/TR/REC-CSS1). The following table shows the supported CSS properties and values as well as their corresponding ActionScript property names. (Each ActionScript property name is derived from the corresponding CSS property name; the hyphen is omitted and the subsequent character is capitalized.)
CSS property ActionScript property Usage and supported values text-align textAlign Recognized values are left,center, right, andjustify.text-decoration textDecoration Recognized values are noneandunderline.margin-right marginRight Only the numeric part of the value is used. Units (px, pt) are not parsed; pixels and points are equivalent. kerning kerning Recognized values are trueandfalse.letter-spacing letterSpacing Only the numeric part of the value is used. Units (px, pt) are not parsed; pixels and points are equivalent. 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: monois converted to_typewriter,sans-serifis converted to_sans, andserifis converted to_serif.display display Supported values are inline,block, andnone.For an example of using styles on XML elements, see An example of using styles with XML.
