FORUMS: list search recent posts

Adding CSS before URLLoading?

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Terrence Dunlop
Adding CSS before URLLoading?
on Mar 2, 2009 at 9:12:37 pm

Does anyone know how to CSS-parse a doc with html tags, have the css style the doc and then pass the doc as data into a URL Loader? A client wants to add to her resume, i want to make sure her additions are styled right.


Return to posts index

Terrence Dunlop
Re: Adding CSS before URLLoading?
on Mar 3, 2009 at 11:03:41 pm

I figured it out. Code is below:

import flash.text.*;

var _html:String;
var _htmlFile:URLLoader;
var _css:StyleSheet;
var _cssFile:URLLoader;

//sets up the URLLoader which loads the css file demo.css
function LoadHTMLCSS() {
_cssFile = new URLLoader();
_cssFile.addEventListener(Event.COMPLETE, onLoadCSS, false, 0, true);
_cssFile.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true);
_cssFile.load(new URLRequest("demo.css"));
trace("demo.css loaded");

//passes the css to a URLLoader which loads the text and tags from resume.html,
//and then formats them with the loaded css doc.
function onLoadCSS(evt:Event):void {
_css = new StyleSheet();
_htmlFile = new URLLoader();
_htmlFile.addEventListener(Event.COMPLETE, onLoadHTML, false, 0, true);
_htmlFile.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true);
_htmlFile.load(new URLRequest("resume.html"));
trace("resume.html loaded");

//then calls an initialize text field method, laying the formatted text in
//a dynamic textField on the stage, instance named "_txtFld."
function onLoadHTML(evt:Event):void {;

function initTextField():void {
_txtFld = new TextField();
_txtFld.x = 410;
_txtFld.y = 20;
_txtFld.width = 450;
_txtFld.multiline = true;
_txtFld.wordWrap = true;
_txtFld.autoSize = TextFieldAutoSize.LEFT;
_txtFld.selectable = false;
_txtFld.styleSheet = _css;
_txtFld.htmlText = _html;
_txtFld.addEventListener(TextEvent.LINK, onTextEvent);

_cssFile.removeEventListener(Event.COMPLETE, onLoadCSS);
_cssFile.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
_htmlFile.removeEventListener(Event.COMPLETE, onLoadHTML);
_htmlFile.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

function onTextEvent(evt:TextEvent):void {

function ioErrorHandler(evt:IOErrorEvent):void {
trace("The following file could not be loaded: " + evt.text);

//make the magic happen, call LoadHTMLCSS.

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved