To the hour, i have not found out a way to avoid importing text into a flash dynamic text field with the correct line break format and i think there is no way to automatically handle this.
While html textareas work fine with the line break \r\n, treating both \r and \n as one single line break, flash reads the \r\n as two line breaks.
The only solution that appears to exist relies on replacing the line breaking characters, once loaded in flash. You can replace the line breaking characters, \r\n with a single \r or a single \n, or with a html <br> tag (in which case you must format the dynamic text to accept html text - see the example below). You can also replace the characters with the flash constant: newline.
Depending on your OS, you will get different line breaks - for linux or unix they are single \r or \n, as opposed to a windows machine which uses \r\n.
Another matter is that i think the text will always be brought into flash with the line breaks, even if you use the php's nl2br function to automatically replace the line breaks into a html <br> tag, but that's something i did not dwell on more.
Example 1 - Dynamic text field treated as HTML
TextField.html = true;
myRawString = "play rune again\r\nin a couple of years";
//replace \r\n with <br>
myCorrectString = myRawString.split("\r\n").join("<br>");dynamicTextField.htmlText = myCorrectString;
Example 2 - Regular dynamic text field with \r or \n
myRawString = "play rune again\r\nin a couple of years";
//remove the \n. works the same with removing \r
myCorrectString = myRawString.split("\n").join("");dynamicTextField.text = myCorrectString;
Example 3 - Regular dynamic text field with flash line breaks
myRawString = "play rune again\r\nin a couple of years";
//replace the \r\n with the flash newline constant
myCorrectString = myRawString.split("\r\n").join(""+newline+"");dynamicTextField.text = myCorrectString;
The dynamic text field has to be set to multiline for this.
No comments:
Post a Comment