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

Line Breaks in Dynamic Text

Explorer ,
Jun 22, 2009 Jun 22, 2009

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?

TOPICS
ActionScript
2.4K
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

Community Expert , Jun 26, 2009 Jun 26, 2009

enable the html property of your textfield and assign htmlText instead of text.

Translate
Community Expert ,
Jun 22, 2009 Jun 22, 2009

enable the ignoreWhite property of your xml instance:

yourxml.ignoreWhite=true;

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
LEGEND ,
Jun 22, 2009 Jun 22, 2009

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.

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 25, 2009 Jun 25, 2009

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.

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
Community Expert ,
Jun 25, 2009 Jun 25, 2009

try:

yourstring = yourstring.split("\r\n").join("\r").split("\n\r").join("\r");

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 25, 2009 Jun 25, 2009

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

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
Community Expert ,
Jun 25, 2009 Jun 25, 2009

then you must be using htmltext, correct?

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 26, 2009 Jun 26, 2009

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);
}

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
Community Expert ,
Jun 26, 2009 Jun 26, 2009

enable the html property of your textfield and assign htmlText instead of text.

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 30, 2009 Jun 30, 2009

That did the trick! Thanks a lot!

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
Community Expert ,
Jun 30, 2009 Jun 30, 2009
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