ForumsProgramming ForumI have a small problem

8 3651
P051D3N
offline
P051D3N
25 posts
Nomad

I am trying to make a function happen when three movie clips have particular x and y functions, (so it is tested on 6 values) on flash AS3. From my time using game maker, I am pretty sure the if function is what I should use, but I don't know any more than that. Help please!

  • 8 Replies
akunu
offline
akunu
35 posts
Nomad

Try this:


addEventListener(Event.ENTER_FRAME, update);
function update(e:Event):void
{
if((mc1.x == 10 && mc1.y == 10) && (mc2.x == 10 && mc2.y == 10) &&(mc3.x == 10 && mc3.y == 10)){
//do something
}
}

That is assuming that your movieclips are named mc1, mc2, and mc3. Just change the 10 to any value. Also, if is not a function, it is a comparison. Neither are x or y, they are values.
gaboloth
offline
gaboloth
1,612 posts
Peasant

Mmm akunu I'm a as2 learning as3 so a little question: are those brackets needed or they are just for simplicity?

Darkroot
offline
Darkroot
2,763 posts
Peasant

The {,} are needed. They tell flash what is part of the function or of the if statement, the ; are not necessary but helps flash.

PixelSmash
offline
PixelSmash
566 posts
Nomad

Adding to that... the () around the comparisons inside the if function are not mandatory, but it can help a lot for reading

beech
offline
beech
107 posts
Nomad

hey everyone! first post! (i'm so proud...lol)

so actually using parenthesis does make a difference in the way that the statement is interpreted. for example:

if( (x==1 && y==1) && z==1 )

in this condition, if if BOTH x=1 AND y=1 the first part results in true - so all of the arguments in this statement must result in true
however:

if( (x==1 || y==1) && z==1 )

in this condition, if EITHER x=1 OR y=1 the first part results in true - so in this case the first part of the condition is only dependent on one of the two values being true.

by surrounding the arguments with parenthesis you are in effect creating a 'sub-condition' or really just an evaluation of the statements inside the parenthesis - actually the 'if' isn't even necessary, try this sometime:

var n:int=1;
trace( (n==1) );

the result of the operation is true - no IFs, ands or butts (lol)

akunu
offline
akunu
35 posts
Nomad

hey everyone!  first post! (i'm so proud...lol)

Welcome to the forums, and armor games in general =3
beech
offline
beech
107 posts
Nomad

thanks akunu - long time fan, first time caller ... LOL!

P051D3N
offline
P051D3N
25 posts
Nomad

Thanks for your help people, you solved my problem;

Showing 1-8 of 8