FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Actionscript 2.0... for and if together = buggy

 


mothmann
Code:

for (n=0;n<2;++n){
     trace(n);
}

this returns 0 1 to the output panel which is desired
but
Code:

for(n=0;n<2;++n){
     trace(n);
     if (n=0) {
        number = 0
     }else if(n=1){
        number=1
     }
}

this will only output 0 in the panel. it never makes it to 1. if you jack up the conditoin to <10 or somsething it will display 0111111111 or something similiar. so any actionscript users out there that can explain to me why?
hexkid
I don't know Actionscript ... but maybe you want to replace the "=" in your tests with "==".
mothmann wrote:
but
Code:

for(n=0;n<2;++n){
     trace(n);
     if (n==0) {       // = is assignment
        number = 0
     }else if(n==1){   // = is assignment
        number=1
     }
}
MrBlueSky
hexkid is right. From ActionScript: The Definite Guide (O'Reilly):

Quote:

We use the equality operator (==) to test whether two expressions have the same value. The equality test takes the general form:

operand1 == operand2

where operand1 and operand2 may be any valid expression. The equality operator can compare operands of any type. When operand1 and operand2 are equal, the expression returns the Boolean value true; when they differ, it returns the Boolean value false. For example:

var x = 2;
x == 1 // false
x == 2 // true

TIP

The equality operator is created using two equal signs in a row (==). It determines whether two expressions are equal and should not be confused with the assignment operator (=) which is used to assign a variable a new value.

Consider this example:

if (x = 5) {
trace ("x is equal to 5")
}

The preceding example does not check whether x equals 5. Instead, it sets x equal to 5. The proper expression is as follows:

// Use == instead of =
if (x == 5) {
trace ("x is equal to 5")
}
mothmann
very nice post MrBlueSky. thanks. I used to be confused on the difference of the two = and == but now it makes sense. thanks.

Also, yes that was the problem. Everything is working fine now. Thanks.
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.