Reputation: 627
I have a basic actionscript code which basically shows a list depending on the value of a text box.
if (txtValue.text = "0")
{
lstFilm.visible = false;
}
else if (txtValue.text = "1")
{
lstFilm.visible = true;
}
The problem i'm having with it is instead of it changing the visibility of the list, it changes the value in the box. Any ideas why or how I could achieve this?
Upvotes: 0
Views: 1753
Reputation: 5241
An if statement typically needs to evaluate a 'true' or 'false' operation.
By using:
if(txtValue.text = "0") { ... }
You are actually assigning the value "0" to the 'text' property of your textfield - In other words you are NOT checking if it is EQUALS-TO "0".
You have to use the double-equals operator to return the desired outcome:
if(txtValue.text == "0") { ... }
This will then pass through your statement correctly.
Only some rare cases, you will wish to do an assignment (instead of 'checking' a condition) within the if-statement. This can often be found in file-reading or reference-checking statements like the following:
var someVar:Array;
if(someVar = methodThatCanReturnList()) { ... }
But this method is a bit frown upon. And for beginners it is much more recommended to master the "==" operator first.
Upvotes: 1
Reputation: 3207
Use ==
which is the equality operator not =
the assignment operator.
Upvotes: 2