Thursday, October 21, 2010

Flash As3 Logic

Weird equalities

= vs. ==

SYMBOL OPERATION EXAMPLES ENGLISH
= assignment myVar = 17 Assign the value 17 to the variable "myVar"
_x = 17 "set the value of the property _x to 17"
== comparison if(_x == 100){
   myVar = 10
}
if the _x property is equal to 100, set the variable "myVar" to 10

more comparisons

SYMBOL OPERATION EXAMPLES ENGLISH
!= NOT EQUAL
tests for inequality
if(myVar != 100){
   myVar = 100
}
if "myVar" is NOT equal to 100, set the variable "myVar" to 100
>= greater than or equal to if(myClip._x >= 100){
   myVar = 10
}
if the _x property of "myClip" is greater than or equal to 100, set the variable "myVar" to 10
<= less than or equal to if(myClip._x <= 100){
   myVar = 10
}
if the _x property of "myClip" is less than or equal to 100, set the variable "myVar" to 10

Checking for more than one condition at once:&& (AND);|| (OR)

if ( (_x < 550) && (_x > 0)) {
     _x = _x+1
}
If the _x property is less than 550 AND the _x property is greater than zero, then add one to the _x property.
note: extra parentheses are used for grouping; they are optional, but they help reading the code.
Example Usage:  
if ( (_x > 550) || (_x < 0)) {
     onStage = false
}
If the _x property is greater than 550 OR the _x property is less than zero, set the variable onStage to f

No comments:

Post a Comment