A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: How to retrieve a TextFields.height property when TextField.autoSize is enabled?

  1. #1
    Junior Member
    Join Date
    Jun 2007
    Posts
    12

    How to retrieve a TextFields.height property when TextField.autoSize is enabled?

    I have a TextField that has the autoSize property set to TextFieldAutoSize.LEFT; and for some reason when I try and retrieve the textField's height property like this "myNumVar = textField.height" it always returns the value of 100, even though the text fields height is nothing like this. Furthermore when I input a larger or smaller amount of text into the field, the height property still returns 100.

    If anyone has any ideas on how I can retrieve an accurate height value then please let me know

  2. #2
    Senior Member jweeks123's Avatar
    Join Date
    Mar 2006
    Posts
    1,124
    are you retrieving the height before or after the autosize property?

  3. #3
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    textField.textHeight

  4. #4
    Senior Member jweeks123's Avatar
    Join Date
    Mar 2006
    Posts
    1,124
    LOL, yeah that works too I supose to be the simplest way.

  5. #5
    Junior Member
    Join Date
    Jun 2007
    Posts
    12
    If I trace the textHeight property after the autoSize property then It returns 0, and if I do the same for the height property then it returns 4. Also I'm trying to retrieve the values of textField dynamically generated by a for statement, so when I trace the height property of all the textFields it stills gives 4, for all 6 of them.

    Update:
    If I trace the height value before the autoSize statement then I get 100 (I assume that's because If I haven't specified a height, then the default is 100), but if I trace it after the autoSize statement then it returns 4. For some reason when the textFields height is adjusted dynamically by the autoSize property then it just gives the same value regardless of the actual height. This is confusing, lol.
    Last edited by AffinityFX; 10-29-2008 at 01:28 PM.

  6. #6
    Senior Member jweeks123's Avatar
    Join Date
    Mar 2006
    Posts
    1,124
    Could you post your source for reference?

    Is this the same loop we worked on earlier today?

  7. #7
    Junior Member
    Join Date
    Jun 2007
    Posts
    12
    Yeah it is, that's the problem with something like this, there's always a million problems to solve, lol.
    for(var i:int = 0; i < blogXMLList.length(); i++) {
    //Create a TextField for each node in the XML
    txtFArr.push(new TextField());
    txtFArr[i].x = textX;
    txtFArr[i].y = textY;
    textY += (txtFArr[i].height + 50);
    txtFArr[i].width = 510;
    txtFArr[i].autoSize = TextFieldAutoSize.LEFT;
    txtFArr[i].wordWrap = true;
    txtFArr[i].border = true;
    txtFArr[i].selectable = false;
    textHolder.addChild(txtFArr[i]);
    txtFArr[i].setTextFormat(postFormat);


    //Load the correct file and load the funtion to place the text in the correct field
    blogPostRequest = new URLRequest(blogXMLList[i].attribute("file"));
    blogPostLoader = new URLLoader();
    blogPostLoader.load(blogPostRequest);
    blogPostLoader.addEventListener(Event.COMPLETE, loadTextIntoField(i));
    }
    The idea is that with a run through of the loop the textY variable will be replaced with the current textfields height, so that the next field can adjust's it's y value accordingly. What I'm trying to make is a blog that has it's posts ordered in the Y coordinate, with a little gap between them, in this case 50 pixels.

  8. #8
    Senior Member jweeks123's Avatar
    Join Date
    Mar 2006
    Posts
    1,124
    Okay, well, let me suggest this.

    How about instead of messing with this issue with the textfields you use a textArea component, that way sizes can be uniform, and you can scroll each post as you wish, and you don't have a really long page.

    You want to give that a go or stick with the textFields?

    If you want to stick with them, take a look at this:


    I tried this:

    Code:
    txt1.text = "abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc";
    
    trace(txt1.height);
    trace(txt1.textHeight);
    
    txt1.autoSize = TextFieldAutoSize.LEFT;
    trace(txt1.height);
    trace(txt1.textHeight);
    with a textfield on stage with an instance name of txt1.

    I traced the textHeight, and height before and after and came up with this:

    17.7
    49
    53
    49

    See how the height property changed after the TextFieldAutoSize?

    Let me know if this helps. If not, we'll try something more.

  9. #9
    Junior Member
    Join Date
    Jun 2007
    Posts
    12
    To be honest I'd rather stick with textFields, as I have already written the code and have it working, to a certain extent. It just seems weird that once a textField has been autoSized, it renders the height property unusable. The text fields I have on the stage at run time are clearly not of height 4, and yet the trace statements says otherwise; every textField, regardless of it's actual size is said to be 4. I must be overlooking something, because it seems to me that the language wouldn't have such a flaw in it. I've searched around on the internet and the only mention of this problem says the fix is to remove the multiline statement, which doesn't help as I haven't used multiline, lol.

    When I trace the textHeight property before and after the autoSize statement, both times it returns 0, which I don't understand. When I trace the height property before it's 100 and after it's 4. I think the reason it's 4 is because I have the wordWrap property set to true, because if I set it to false the textfield shrinks to a single line and does actually look like it has a height of 4. So I think what is happening is that the autoSizing effects the behaviour of the textField, but doesn't actually adjust the height property accordingly. But even this doesn't really help!

    By the way I really appreciate your help today and yesterday! I'll have a play with the code and see if I can sort it out

  10. #10
    Junior Member
    Join Date
    Jun 2007
    Posts
    12
    I've just figured it out! The problem was that I was trying to retrieve the height of a text field that hadn't received it's text yet, therefore hadn't resized and therefore hadn't changed it's height. So what I did was I specified the Y of the textFields when all the text had been loaded and resized and it worked. Again thanks for your help!

  11. #11
    Senior Member jweeks123's Avatar
    Join Date
    Mar 2006
    Posts
    1,124
    Cool, and no problem, glad i could help. Let me know if there's anything else I can do to help.

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