Answered
Applying CSS to XML data in AS3
I realize this topic has been repeated several times, but despite having reviewed many discussions and web pages on the subject I've not been able to figure out why mine isn't working, so I'm looking for help.
Here is my relevant code:
CSS:
@charset "utf-8";
/* CSS Document */
p {
font-family:Arial;
font-size:25px;
color:#000;
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<tbContent>
<slide> <!-- 0 -->
<title>Table of Contents</title>
<type>content</type>
<content><![CDATA[<p>What is a Mantoux Skin Test?</p>
<p>How to Administer a Mantoux Skin Test</p>
<p>How to Read a Mantoux Skin Test</p>
<p>How to Interpret the Reading</p>]]></content>
<image>Blank.jpg</image>
<popup>0</popup>
<footnote>0</footnote>
</slide>
</tbContent>
AS3:
var container:content_mc = new content_mc();
// Set up the xml file objects
var xmlData:XML = new XML();
XML.ignoreWhitespace = true;
var xmlLoader:URLLoader = new URLLoader();
// CSS external document
var cssLoader:URLLoader = new URLLoader();
var cssRequest:URLRequest = new URLRequest("css.css");
var styles:StyleSheet = new StyleSheet();
cssLoader.load(cssRequest);
cssLoader.addEventListener(Event.COMPLETE, onCSSComplete);
function onCSSComplete(e:Event):void {
styles.parseCSS(cssLoader.data);
xmlLoader.load(new URLRequest("xml.xml"));
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
trace ("CSS has loaded.");
}
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
parseFile(xmlData);
}
function parseFile(xmlContent:XML):void {
stage.addChild(container);
var contents:TextField = new TextField();
contents.styleSheet = styles;
contents.htmlText = xmlContent.slide.content.text()[slide];
contents.width = xW;
contents.x = xSet;
contents.y = ySet;
contents.antiAliasType = "advanced";
contents.multiline = true;
contents.autoSize = "left";
contents.wordWrap = true;
container.addChild(contents);
}
The text appears on the stage, but with no formatting. I'm not getting any errors. If anyone can help with this it would be greatly appreciated.
