PDA

View Full Version : AS3 and CSS. This has gotta be something stupid I'm doing



studlybw
May 12th, 2009, 05:52 PM
I can't, for the life of me get my dynamic text box to apply the CSS stylesheet that I've linked. The loader is definitely loading the css and I get a good trace of the css but the text shows up with it's orignal formatting. The dynamic text box is definitely set up to render htmlText and it does. Just won't apply the stylesheet. Here's my code

style.css


p{
font-family:Arial, Helvetica, sans-serif;
font-size: 14px;
color: #FFFFFF;
}
h1{
color: #00FFFF;
font-size: 12px;
}

a{
color: #0066FF;
text-decoration: underline;
}
my actionscript


//Declare variables
var cssLoader:URLLoader = new URLLoader();
var cssRequest:URLRequest = new URLRequest("imports/style.css");
var sheet:StyleSheet = new StyleSheet();

//Load css
cssLoader.load(cssRequest);
cssLoader.addEventListener(Event.COMPLETE, addText);

//Add text to the dynamic text box named "txt" on the stage
function addText(event:Event):void
{
trace(cssLoader.data);
sheet.parseCSS(cssLoader.data);
txt.styleSheet = sheet;
}
txt.htmlText = "<p>This is a paragraph</p>" + "<a>This is a link</a>";

studlybw
May 12th, 2009, 07:35 PM
I have no idea why this would be but I had to use single quotes, and not double quotes, around the string that I was inputting. It took me about 7 hours to figure that out and I still don't understand why.