PDA

View Full Version : running function



dilpreet
July 16th, 2009, 01:05 AM
Hey guys

How do i get function to run again and again. I have this thing where i want to check 5 textfields if they have any text in them.

I made a function


function test(){
if(q_txt.text == "" && a1_txt.text == "" && a2_txt.text == "" && a3_txt.text == "" && a4_txt.text == "" )
{
compile_btn.visible = true;
compile = true;
}
else
{
compile_btn.visible = false;
compile = false;
}
}
test();
but this function only runs once and once it's run if i type in any thing in the text field it doesn't do anything.

How do i get it to check again and again

IQAndreas
July 16th, 2009, 01:37 AM
Basically, what you are saying is "If all textFields are blank, let the user compile it."

I'm sure you mean "If any textField is blank, do not let the user compile it."

q_txt.addEventListener(Event.CHANGE, checkText);
a1_txt.addEventListener(Event.CHANGE, checkText);
a2_txt.addEventListener(Event.CHANGE, checkText);
a3_txt.addEventListener(Event.CHANGE, checkText);
a4_txt.addEventListener(Event.CHANGE, checkText);

function checkText(ev:Event):void
{
if(q_txt.text != "" && a1_txt.text != "" && a2_txt.text != "" && a3_txt.text != "" && a4_txt.text != "" )
{
compile_btn.visible = true;
compile = true;
}
else
{
compile_btn.visible = false;
compile = false;
}
}
That will check each and every time something changes in a textField.

dilpreet
July 16th, 2009, 01:45 AM
thanx but i don't know how u thought i meant "If all textFields are blank, let the user compile it."

the function says that if all text fields are blank make the compile button visible and if they aren't blank hide the compile button

Gnoll
July 16th, 2009, 02:03 AM
He just copied the content from your function? :P

Gnoll