Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Brain Cloud - Why is function running? 1

Status
Not open for further replies.

fedtrain

Instructor
Jun 23, 2004
142
US
Here is what is most probably a dumb question, but my brain has stopped being able to analyze....

Simple function, and then a button that is supposed to call that function. But the function is being called with out the button being clicked.

What is going on?

Code:
mcBox._visible = false;
var btOne:Button

function changeColor(){
	if (mcBox._visible == true){
		mcBox._visible = false;
	}
	else {
		mcBox._visible = true;
	}
}
trace (mcBox._visible);

btOne.onRelease = changeColor();

This always shows the box as visible. If I comment out the button.onRelease...then the box stays false but what is wrong?

I so can't see it.

"Credit belongs to the man who is actually in the arena - T.Roosevelt
 
[tt]mcBox._visible = false;
var btOne:Button;
function changeColor() {
if (mcBox._visible == true) {
mcBox._visible = false;
} else {
mcBox._visible = true;
}
}
trace(mcBox._visible);
btOne.onRelease = function() {
changeColor();
};[/tt]

(You don't need "var btOne:Button;" by the way.)

Kenneth Kawamoto
 
Thank you very much...that would have just sat in my head all day distracting me.

So...no calling the function...I have to put it in the function brackets...weird. I looked at much of my old code, but I guess this was too simple for what I was looking at, and couldn't get my brain around it.

As for declaring the button...just doing that because a class I took really hyped declaring your variables, it makes the hints pop up when typing.

Dave

"Credit belongs to the man who is actually in the arena - T.Roosevelt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top