A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] htmlText and empty lines

  1. #1
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312

    resolved [RESOLVED] htmlText and empty lines

    I am having the most frustrating time with htmlText in TextField.

    apparently, if you set the htmlText of a TextField, you always get an extra line at the end.

    Here is what I have found out:

    Below, a multiline TextField is created and the text property is set. I then grab the htmlText property, set the htmlText to "" and then reapply the htmlText I had just grabbed. This causes a new line to be added to the Textfield:
    Actionscript Code:
    var tf:TextField = new TextField();
    tf.width = tf.height = 200;
    tf.border = true;
    tf.multiline = true;
    tf.wordWrap = true;
    addChild(tf);

    tf.text = "this is not htmlText";
               
    trace(tf.numLines); // 1
               
    var tfHTMLText:String = tf.htmlText;
    tf.htmlText = "";
    tf.htmlText = tfHTMLText;
           
    trace(tf.numLines); // 2
    If I remove the line tf.htmlText = "", I do not get the new line. Try it. My understanding is that the value of the htmlText did not actually change, so flash does nothing.


    Suppose I change the code so I do not ever say tf.htmlText = "". Instead, I modify the 'tfHTMLText' and then set the new value. (I slice the html so that the characters I inject end up inside all of the html tags, otherwise, flash creates more tags to wrap the new text). This still causes the new line to occur, suggesting that if the htmlText is modified, it will always append a new line.
    Actionscript Code:
    var tf:TextField = new TextField();
    tf.width = tf.height = 200;
    tf.border = true;
    tf.multiline = true;
    tf.wordWrap = true;
    addChild(tf);
    tf.text = "this is not htmlText";

    trace(tf.numLines); // 1

    var tfHTMLText:String = tf.htmlText;
    var newHTMLText:String = tfHTMLText.slice(0, 105);
    newHTMLText += "sdjkhfg";
    newHTMLText += tfHTMLText.slice(105, tfHTMLText.length);
    tfHTMLText = newHTMLText;
    tf.htmlText = tfHTMLText;

    trace(tf.numLines); // 2

    More information:

    add the trace statement below to the code above. you will see that the line of text is empty. nothing in it.
    Actionscript Code:
    trace("last line text = '" +tf.getLineText(tf.numLines - 1) + "'"); //last line text = ''

    also, the textHeight property of the textfield does not include this empty line. add the code below to see this fact:
    Actionscript Code:
    trace("tf.textHeight = " + tf.textHeight); // tf.textHeight = 15
    var metricHeights:Number = 0;
    for (var i:int = 0; i < tf.numLines; i++)
        metricHeights += tf.getLineMetrics(i).height;
    trace("metrics height = " + metricHeights); //metrics height = 30


    I have yet to find a way to remove that line. I am currently working on a utility that is breaking because of this extra line. Unfortunately, the first utility that causes this extra line to occur must modify the htmlText otherwise it will not work.

    Any suggestions on how to remove this extra line?
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


  2. #2
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    and of course, i find the solution myself shortly after i post on a forum.

    well, here is the solution.

    if you care about removing the empty line of text that flash creates when modifying the htmlText property of a TextField, simply call this function after you are done, and the line goes away:

    Actionscript Code:
    tf.replaceText(tf.length - 1, tf.length, "");

    stupid flash.
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


  3. #3
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    I just wanted to note, that again, my solution came from scouring the asDocs online and experimenting with solutions. I doubt many will read this comment, but 90% of my solutions come from looking at the asDocs and experimenting.

    Try reading them: http://help.adobe.com/en_US/FlashPla...ctionscript/3/
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center