Copy link to clipboard
Copied
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 > 8) {
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!
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;
}
};
Copy link to clipboard
Copied
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;
}
};
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
The first paragraph thrills me as it opens "new horizons"...
🙂
But the second scares me!
I tried some AS3 a few years ago and I found it a bit too complicated for my 72 brain...
I think I'll try to improve my knowledge in AS2 instead wasting time to learn AS3...
😞
Find more inspiration, events, and resources on the new Adobe Community
Explore Now