New Media Fun

Having fun in an online world

Archive for February, 2010

BulkLoader and CSS

Posted by admin under Flash, HTML

I have become a big fan of using BulkLoader. It is a great class library that allows me to load many different types of files in a controlled and organized fashion. However, it isn’t clear on how to load CSS.

I assumed I would be able to use a “getCSS” function, but there isn’t one coded into the class structure.

To get around this I used the loaded CSS file as a String and then used the parseCSS() function to convert the String into a usable CSS Object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// create the loader instance
var loader:BulkLoader = new BulkLoader("cssLoading");

var css:StyleSheet;
var cssURL:String = "myCSS.css";

loader.add(cssURL);

...

 // when loader is complete
 function parseCSS():void{
  // place the loaded CSS into a string
  var cssContent:String = String(loader.getContent(cssURL))
 
  css = new StyleSheet();
  css.parseCSS(cssContent);

  // trace should output '[object StyleSheet]'
  trace(" Loaded Style Sheet: " + css);
 }

Hope this can be helpful for others.

This is the future of in home production:

Some day I will get my hands on this or the Makerbot