A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: How to detect resize event of a TextField

  1. #1
    Member
    Join Date
    Aug 2008
    Posts
    38

    How to detect resize event of a TextField

    I have a TextField with autoSize = true.
    So, when the TextField gets resized (because of the size of the text), I want to react to this event (the resize).
    Something like:
    TextField.onResize.

    Is there a way to do it?

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    No, there's no such event, however, there is an event for when the content of your textfield has been change, which would be the same as when the size changes, because when you add or remove text from your textfield, it will auto-resize again. It's called

    TextField.onChanged
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Member
    Join Date
    Aug 2008
    Posts
    38
    Thanks Nig, but it's not what I want.

  4. #4
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    I think you do want that, because your Text Field's size will only be changed when someone types something into, then it will expand, correct? Then it would be the same if you used onChanged event, because it is fired when the text of your Text Field is changed, and also when you're text is changed, the size of your Text Field has been changed, if you know what I mean.

    DOWNLOAD SAMPLE FILE
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  5. #5
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    but I know what you mean as well, but sadly there is no built-in Event onResize event for Text Fields in AS2, BUT, there is however a way around this to make your own Event. This code is far more difficult, but since you really want an onResize event, this is the only way (in the example, I am supposing the textfield's instance name is, txt):

    Actionscript Code:
    TextObject = new Object();
    AsBroadcaster.initialize(TextObject);

    txt.autoSize = true;

    txtSize = txt._width;

    onEnterFrame = function(){
        if(txt._width != txtSize){
            txtSize = txt._width;
            TextObject.broadcastMessage("onResize");
        }
    }

    resizeListener = new Object();
    resizeListener.onResize = function(){
        trace("TextField has been resized!");
    }
    TextObject.addListener(resizeListener);

    Despite its complexity, the code is also bad and uses up memory because of the unnecessary onEnterFrame loop, which could've been replaced with onChanged event, but then we could just use the code provided in my previous post instead
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  6. #6
    Member
    Join Date
    Aug 2008
    Posts
    38
    Nig thanks a lot, I might try it.

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