Apply CSS to HTML in Flash ActionScript 3.0 - Step 5: Loading the CSS file
Posted by : FireCode on Sep 03, 2010
Now let's write our code. Press F9 inside the Flash IDE to bring up the Actions editor.

First we're going to load our CSS file. This piece of code loads our CSS file, using an event listener (Event.COMPLETE) to take care of the data once it is loaded.
var _css:URLLoader = new URLLoader();
_css.load(new URLRequest("style.css"));
_css.addEventListener(Event.COMPLETE, StyleLoaded, false, 0, true);
function StyleLoaded($e:Event):void
{
}
Once our CSS file is fully loaded we need to store it as an instance of the StyleSheet Class. To know more about this class, please read this link: live docs
First we have to create an instance of the StyleSheet Class at the beginning of our code. After that we can simply parse the CSS data and store it.
var _style:StyleSheet = new StyleSheet();
var _css:URLLoader = new URLLoader();
_css.load(new URLRequest("style.css"));
_css.addEventListener(Event.COMPLETE, StyleLoaded, false, 0, true);
function StyleLoaded($e:Event):void
{
_css.removeEventListener(Event.COMPLETE, StyleLoaded);
_style.parseCSS(_css.data);
}

no comment
Add comment