Copy link to clipboard
Copied
I've finally got XML information coming into my text field (thanks Ned!). Only problem now is that there for every line break in the text, Flash reads it as two line breaks, for example:
XML:
Line 1
Line 2
Flash:
Line 1
Line 2
I've searched forums and tutorials and found that you can just use the <br> tag in the original text or if I'm using actionscript to input the text I can use \n or \r but what if I'm using text generated by a CMS which my client needs to be able to use?
enable the html property of your textfield and assign htmlText instead of text.
Copy link to clipboard
Copied
enable the ignoreWhite property of your xml instance:
yourxml.ignoreWhite=true;
Copy link to clipboard
Copied
Although I would suggest that any XML loaded text that you plan to display in Flash should probably be wrapped in a CDATA tag and ignoreWhite won't affect that. If you plan to use things like <B> tags and all the CDATA prevents the XML parser from seeing that tag as another childnode.
I think part of the problem is that certain text editors put both a linefeed (\n) and return (\r) into their text streams.
We have a lot of problems with this and I don't really have any good solutions.
Copy link to clipboard
Copied
Thanks for the replies.
I was actually already using ignore.white but it wasn't working.
Just tried wrapping the XML in CDATA tags but that didn't work either.
Copy link to clipboard
Copied
try:
yourstring = yourstring.split("\r\n").join("\r").split("\n\r").join("\r");
Copy link to clipboard
Copied
WOO-HOO!!!
That did it, thanks so much!
Only problem is that seems to have cancelled the CSS styling I had applied to portions of the text
Copy link to clipboard
Copied
then you must be using htmltext, correct?
Copy link to clipboard
Copied
No, actually. This is the script I'm using:
// load css
var format = new TextField.StyleSheet();
var path = "http://www.website.com/flash.css";
format.load(path);
vacancy_list_arr = new Array();
vacancy_list_xml = new XML();
vacancy_list_xml.ignoreWhite = true;
vacancy_list_xml.onLoad = function(success) {
if (success) {
var job_xml = vacancy_list_xml.firstChild.firstChild;
while (job_xml != null) {
// add the job data to our vacancy_list_arr
vacancy_list_arr.push(getTrackData(job_xml));
job_xml = job_xml.nextSibling;
}
} else {
trace("Error loading vacancy_list.");
}
delete vacancy_list_xml;
for(i=0; i<vacancy_list_arr.length; i++){
var jobPosition = "<p class='red'>Job Position</p>"
var jobLocation = "<p class='red'>Location</p>"
var jobDescription = "<p class='red'>Description</p>"
detailText.styleSheet = format;
detailText.text = jobPosition + vacancy_list_arr.Headline + newline + newline + jobLocation + vacancy_list_arr.Location + newline + newline + jobDescription + vacancy_list_arr.Description;
detailText.text = detailText.text.split("\r\n").join("\r").split("\n\r").join("\r");
}
}
//
function getTrackData(job_xml) {
// convert data to object form
var jobData = new Object();
var data_xml = new XML();
data_xml = job_xml.firstChild;
while (data_xml != null) {
jobData[data_xml.nodeName] = data_xml.firstChild.nodeValue;
data_xml = data_xml.nextSibling;
}
return jobData;
}
// load xml after css is loaded
format.onLoad = function(success){
vacancy_list_xml.load("http://www.website.com/jobdetail.asp?NID="+_root.moreGlobalData);
}
Copy link to clipboard
Copied
enable the html property of your textfield and assign htmlText instead of text.
Copy link to clipboard
Copied
That did the trick! Thanks a lot!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now