views:

445

answers:

1

Hi All,

I am looking for something equivalent to the "mx:Style" tag in Flex for actionscript 3. Currently I am loading the skin using StyleManager.loadStyleDeclaration().

But this loads the skin at runtime which is not my intention. Thus am looking for something similar to "mx:Style" tag in as3 such that it embeds the skin and is not required to load at runtime.

Many thanks for any replies.

Ashish.

A: 

From here

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;
  }
 }
}
Chris Klepeis