Reputation: 23
I make a textfield named 'nama' and button 'ayo'. I want to make the button disable when the textfield is empty. But when I try this code my button not disable and still working. I want the button disable before the textfield filling.
stop();
menumulaikuis();
var namasiswa:String;
var nama:TextField = new TextField();
namasiswa = nama.text;
nama.addEventListener(Event.CHANGE,handler);
function handler(event:Event){
if (nama.text) {
ayo.enabled = true;
ayo.visible = true;
} else {
ayo.enabled = false;
ayo.visible = false;
}
}
Upvotes: 0
Views: 270
Reputation: 26
If the Text Field isn't for user input, you cannot use the Event.CHANGE
listener.
I suggest changing Event.CHANGE
to Event.ENTER_FRAME
; that should fix your problem.
Upvotes: 0
Reputation: 9839
You have some little problems in your code :
addChild()
: var nama:TextField = new TextField(); addChild(nama);
input
: nama.type = 'input';
if(nama.text == ''){ /* ... */ }
So your text field's change handler can be like this :
function changeHandler(event:Event): void
{
if (nama.text != '') {
ayo.enabled = true;
ayo.visible = true;
} else {
ayo.enabled = false;
ayo.visible = false;
}
}
Hope that can help.
Upvotes: 1