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

Paragraph spacing in Dynamic Text Field

Explorer ,
Mar 26, 2009 Mar 26, 2009
I have a dynamic text field that's being loaded with text from an external xml file. The data can contain a carriage return if entered by the user to force a line break.

All is working except that the textfield displays a gap equivalent to about two lines between the first and second line when the data contains a carriage return.

I can't seem to find a way to set the line height or paragraph height for the textField to make the line spacing tighter. Any suggestions?
TOPICS
ActionScript
3.7K
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
New Here ,
Mar 29, 2009 Mar 29, 2009
it seams that flash treat your carriage return as a new paragraph. You cant set line height or paragraph directly on the TextField, instead you need to attach a style sheet, or a TextFormat.

var aNumber = 4;
var myTextFormat = new TextFormat();
myTextFormat.leading = aNumber; (distance between lines)
yourTextField.defaultTextFormat = myTextFormat;

or better a style sheet

for more help with style sheets just consult the adobe documentation.
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 ,
Mar 29, 2009 Mar 29, 2009
You can try "leading" property of TextFormat or "leading" prperty of StyleSheet.

Also, you may want to remove carriage returns and such (or replacing them with entities of your liking such as <br>) before you place text into the TextField via RegEx:

var regexPattern:RegExp = /\n|\r/g;
var str:String = "one line\nano\rther line \nthird \nline.";
trace(str.replace(regexPattern, ""));
or
trace(str.replace(regexPattern, "<br>"));


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 ,
Mar 30, 2009 Mar 30, 2009
LATEST
I tried adding a leading value on the textField. I didn't think to try it with a textFormat.

My solution was to create a function to filter the input text. The function splits the input string using [\r\n] as the delimiter pattern. Then it wraps each string in the resulting array with <p> and </p> and returns.

Instead of adding the string to textField.text it's added to textField.htmlText. This solution seems to work.

I may experiment with the leading property more when I have a chance.

Thanks for the input.
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