Stylesheets without external CSS file AS3

Just a wee code snippet in case I need it again one day. Adding stylesheet functionality I’d usually use external CSS for from within the actionscript. Pretty easy:

static private function setStyleSheet():void
{
styleSheet = new StyleSheet();

// create object for each style

//links
var a:Object = 
{
color: "#FF0000"
}
styleSheet.setStyle("a", a);

var hover:Object = 
{
color: "#FF9900"
}
styleSheet.setStyle("a:hover", hover);

var active:Object = 
{
color: "#000000"
}
styleSheet.setStyle("a:active", active);



}

Then if I wanted to assign that stylesheet to a TextField, I’d go:

MyTextField.styleSheet = styleSheet;
Tech Reference:

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑