|
-
css/xml issues - probably an easy fix :)
I've been playing with this all day - I've managed to apply CSS to a textfield, and managed to get my XML formatted correctly in the text field ... however ... i can't get my XML formatted correctly WITH the CSS applied. What am I doing wrong?
Here is my AS:
Code:
var news_styles = new TextField.StyleSheet();
news_styles.setStyle("title", {
color:'#000000',
fontSize:'12',
display:'block'
});
news_styles.setStyle("date", {
color:'#000000',
fontSize:'18',
display:'block',
fontWeight:'bold'
});
news_styles.setStyle("message", {
color:'#666666',
fontWeight:'bold',
fontStyle:'italic',
display:'inline'
});
news_styles.setStyle("a:link", {
color:'#FF0000'
});
news_styles.setStyle("a:hover", {
textDecoration:'underline'
});
news_txt.styleSheet = news_styles;
//news_txt.text = storyText;
var newsXML:XML = new XML();
newsXML.ignoreWhite = true;
newsXML.load("newsxml.xml");
news_txt.autoSize = true;
//var xml_styles = new TextField.StyleSheet();
newsXML.onLoad = function(success) {
if (success) {
var newsBits:Number = newsXML.firstChild.childNodes.length;
var node = newsXML.firstChild.childNodes;
for (var i = 0; i<newsBits; i++) {
news_txt.text += node[i].childNodes[0].firstChild.nodeValue + " > ";
news_txt.text += node[i].childNodes[1].firstChild.nodeValue + newline;
news_txt.text += node[i].childNodes[2].firstChild.nodeValue + newline + newline;
}
}
};
and here is my XML (it's actually a PHP file, but it gets extracted as follows
Code:
<?xml version="1.0"?>
<site><news>
<title>A new hat!</title>
<date>2005-10-12</date>
<message>I bought a new hat today. It's red and blue and purple and house.</message>
</news>
<news>
<title>Begin</title>
<date>2005-10-09</date>
<message>This is the first post!</message>
</news>
</site>
Thanks
-
Code:
var styles:TextField.StyleSheet = new TextField.StyleSheet();
styles.setStyle("title", {
color:'#C9C9C9',
display:'inline'
});
styles.setStyle("date", {
color:'#C9C9C9',
display:'block'
});
styles.setStyle("message", {
color:'#8A8A8A',
display:'block'
});
styles.setStyle("a:link", {
color:'#242424'
});
styles.setStyle("a:hover", {
textDecoration:'underline'
});
var my_xml:XML = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success:Boolean):Void {
if (success) {
news_txt.styleSheet = styles;
news_txt.autoSize = true;
//news_txt.text = my_xml;
var newsBits:Number = my_xml.firstChild.childNodes.length;
var node = my_xml.firstChild.childNodes;
for (var i = 0; i<newsBits; i++) {
//news_txt.htmlText += node[i].childNodes[0] + " > " + node[i].childNodes[1];
news_txt.htmlText += node[i].childNodes[0] + " > ";
news_txt.htmlText += node[i].childNodes[1] + newline;
news_txt.htmlText += node[i].childNodes[2];
news_txt.htmlText += "---" + newline;
}
} else {
trace("Error loading XML.");
}
};
my_xml.load("newsxml.xml");
got it !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|