Here we go again - can Flash developers make this any more difficult?
I’m trying to apply some CSS to a textfield with an actionscript assigned variable: “press”. The CSS doesn’t seem to apply when the XML nodes are parsed. When I create a textfield within Flash the CSS works fine, but not if I create the textfield with actionscript. Why???
I hope we can all learn something from this. Files are attached.
//Create textfield
this.createTextField("content_txt", 10, 0, 0, 390, 0);
//Create and load styles
var pressStyle:TextField.StyleSheet = new TextField.StyleSheet();
pressStyle.load("news.css");
content_txt.styleSheet = pressStyle;
//Textfield attributes
content_txt.multiline= true;
content_txt.wordWrap = true;
content_txt.html = true;
content_txt.autoSize = true;
content_txt.variable = "press";
/*
// Code below works but doesn't parse XML nodes
newsXML = new XML();
newsXML.ignoreWhite = true;
newsXML.load("newsPress.xml");
newsXML.onLoad = function () {
content_txt.htmlText = newsXML;
}
*/
newsXML = new XML();
newsXML.onLoad = pressLoad;
newsXML.load("newsPress.xml");
function pressLoad(OK) {
if (OK == true) {
Publish(this.firstChild);
//content_txt.htmlText = newsXML;
}
}
function Publish(HeadlineXMLNode) {
if (HeadlineXMLNode.nodeName.toUpperCase() == "BROADCAST") {
press = ""; // Removes "undefined" instance
story = HeadlineXMLNode.firstChild;
while (story != null) {
if (story.nodeName.toUpperCase() == "STORY") {
lead = "";
body = "";
URL = "";
element = story.firstChild;
while (element != null) {
if (element.nodeName.toUpperCase() == "LEAD") {
lead = element.firstChild.nodeValue;
}
if (element.nodeName.toUpperCase() == "BODY") {
body = element.firstChild.nodeValue;
}
if (element.nodeName.toUpperCase() == "URL") {
URL = element.firstChild.nodeValue;
}
element = element.nextSibling;
}
press += "<font color='#B2B2B2'><a href='"+URL+"' target='_blank'>"+lead+"</a></font><br>";
// Don't add font size here
//content_txt.htmlText += "<font color='#B2B2B2'><a href='"+URL+"' target='_blank'>"+lead+"</a></font><br>";
}
story = story.nextSibling;
}
}
}