all groups > flash actionscript > april 2005 >
You're in the

flash actionscript

group:

if...and statement in ActionScript?


if...and statement in ActionScript? tpolson
4/16/2005 12:00:00 AM
flash actionscript:
i have a conditional statement the requires "if (condition) and (condition)
then (result) end if"

This statement obviously doesn't work, but it shows what i'm going for. are
there any other ways of creating this logic statement?

if (x=0) and (y>0) {
dropbit=1
} else {
dropbit=0
}
Re: if...and statement in ActionScript? tpolson
4/16/2005 12:00:00 AM
nevermind. this works.

if (x=0) && (y>0) {
dropbit=1
} else {
dropbit=0
Re: if...and statement in ActionScript? I flash therefore I am
4/16/2005 12:00:00 AM
if( x == 0 and y > 0 ) {

dropbit = 1;

} else {

dropbit = 0;

}

or, more simply

dropbit = ( x == 0 and y > 0 );


[quoted text, click to view]

Re: if...and statement in ActionScript? I flash therefore I am
4/16/2005 12:00:00 AM
Are you REALLY sure? I don't think so.


Re: if...and statement in ActionScript? David Powers
4/16/2005 12:00:00 AM
[quoted text, click to view]

if (x=0) will *always* equate to true, and it will change the value of
x, if it's anything other than zero. A single equals sign is the
assignment operator. It assigns the value 0 to x; it doesn't check the
value.

To check the value, you need to use the equivalent operator (==). I
Flash therefore I am's solution is correct.

--
David Powers
Author, "Foundation PHP 5 for Flash" (friends of ED)
Co-author "PHP Web Development with DW MX 2004" (Apress)
Re: if...and statement in ActionScript? Jeckyl
4/16/2005 12:00:00 AM
Some people think "works" means "I get no error messages". That's not the
same thing. There is lots of perfectly valid syntax that is absolute
rubbish or does something completely different to what you may be wanting to
do. Working means that it does what you need it to do .. not just that
there are no error messages !!!
--
Jeckyl

Re: if...and statement in ActionScript? Byron Canfield
4/16/2005 10:58:02 AM
You may THINK it's working, but it's not -- for two reasons. Aside from the
improper equality comparison, the distribution of parenthetical enclosures
is wrong, and would generate an error if you ran the syntax checker. Should
be either

if ((x==0) && (y>0)) {

or, more simply:

if (x==0 && y>0) {

[quoted text, click to view]

AddThis Social Bookmark Button