Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Applying CSS to XML data in AS3

Explorer ,
Jun 09, 2010 Jun 09, 2010

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.

TOPICS
ActionScript
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Jun 09, 2010 Jun 09, 2010

The default parser doesn't like the charset decl in css:

@charset "utf-8";

Remove line from the file and you should be ok. Alternatively, you could write your own parser -- or strip the declaration out.

Translate
Guest
Jun 09, 2010 Jun 09, 2010

The default parser doesn't like the charset decl in css:

@charset "utf-8";

Remove line from the file and you should be ok. Alternatively, you could write your own parser -- or strip the declaration out.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 09, 2010 Jun 09, 2010

Fabulous!! Thank you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 09, 2010 Jun 09, 2010
LATEST

You're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines