February 2010
M T W T F S S
« Jan   Mar »
1234567
891011121314
15161718192021
22232425262728

Styling loaded html content

Problem
Need add css for loaded html content

Solution
Using URLRequest and URLLoader. Also using methods parseCSS and styleSheet.

Detailed explanation
as code:

var myTextObject:URLRequest=new URLRequest("my_content.txt");
var myLoaderObject:URLLoader = new URLLoader();

var myCssObject:URLRequest=new URLRequest("style.css");
var myCssLoaderObject:URLLoader = new URLLoader();

myLoaderObject.addEventListener(Event.COMPLETE,
myContentWasLoaded);
myLoaderObject.load(myTextObject);

myCssLoaderObject.addEventListener(Event.COMPLETE, myCssWasLoaded);
myCssLoaderObject.load(myCssObject);

function myContentWasLoaded(e:Event):void {
myContent_txt.htmlText=myLoaderObject.data;
}

function myCssWasLoaded(e:Event):void {
var myCss:StyleSheet= new StyleSheet();
myCss.parseCSS(myCssLoaderObject.data);
myContent_txt.styleSheet=myCss;
}

css code:


a {
color: #ff0000;
}
a:hover {
color: #9C09C0
}

index

Source:
slyling_loaded_html_content

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>