Skip to main content
Known Participant
January 5, 2013
Answered

Listener problem...

  • January 5, 2013
  • 1 reply
  • 739 views

Hi there!

I need to control the visibility of a button depending of the length of any of three differents Text Fields.

I wrote this:

var allNewFldsListener:Object = new Object();

allNewFldsListener.onChanged = function(newEmailFld:TextField, newFirstAltEmailFld:TextField, newSecondAltEmailFld:TextField) {

    if (newEmailFld.length > 8 || newFirstAltEmailFld.length > 8 || newSecondAltEmailFld.length > 😎 {

        verifBtn._visible = true;

    }

    else {

        verifBtn._visible = false;

    }

};

addListener(allNewFldsListener);

The listener is supposed to make verifBtn visible if any of the three text fields has a length of more than eight characters.

But it doesn't...

Would you please tell me why?

Many thanks in advance for your explanations/precisions/corrections!

This topic has been closed for replies.
Correct answer Ned Murphy

Just use the onChanged event/handler of the textfields themselves...

newEmailFld.onChanged = newFirstAltEmailFld.onChanged = newSecondAltEmailFld.onChanged = checkText;

function checkText(textfield_txt:TextField){ 

    if (textfield_txt.length > 8) {
        verifBtn._visible = true;
    } else {
        verifBtn._visible = false;
    }
};

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
January 5, 2013

Just use the onChanged event/handler of the textfields themselves...

newEmailFld.onChanged = newFirstAltEmailFld.onChanged = newSecondAltEmailFld.onChanged = checkText;

function checkText(textfield_txt:TextField){ 

    if (textfield_txt.length > 8) {
        verifBtn._visible = true;
    } else {
        verifBtn._visible = false;
    }
};

Germaris1Author
Known Participant
January 5, 2013

Hello Ned!

Thank you for this simple solution which, of course, works nice.

It's kind of Listener which doesn't wear the name "Listener", true?

Best regards,

Gerard

Ned Murphy
Legend
January 6, 2013

Yes, you could put it that way.  If you look at the various interface objects in the help files you will see that they have events associated with them that you can "listen" for by just assigning a function (event handler) to those events.

If you ever move up to AS3 you will find this aspect to be much more clear, prominent and consistent, as most all objects have events and you literally assign event listeners and event handlers for the listeners.  While some complain about the extra coding that can result, it becomes much easier to understand when they are all managed in the same way.