PDA

View Full Version : If statements, again not making sense?



darthmahon
January 10th, 2005, 08:32 AM
Hi,

Using the following to move one item to a certain place once the first item has reached there:


if (mc_skip._y - 1 < 20 && mc_skip._y + 1 > 20) {
mc_skip._y = 20;
mc_skip_b._y = 20;
//the movieclip is within 1 point of where you want it
}

this.onEnterFrame = function(){
trace("Button:" + mc_skip_b._y);
trace("Text:" + mc_skip._y);
}


Ok, so really, why does the mc_skip_b not move to 20 _y? I am tracing it, and it's definately going to 20 _y so I don't get it?

Cheers,
Chris

arcaRox
January 10th, 2005, 10:09 AM
Your If condition is mutually exclusive. Either mc_skip._y - 1 is going to be less than 20 or mc_skip._y + 1 is going to be greater than 20. You cannot have both of them happening at the same time as required by the && operator.

This looks like a typo, since you have a similarly named mc_skip_b variable inside the If.

kiliaan856
January 10th, 2005, 03:31 PM
(mc_skip._y - 1 < 20 && mc_skip._y + 1 > 20)

This could evaluate to be true if both were mc_skip._y was 19> and <21

20 - 1 = 19

20 + 1 = 21

therefore:

if(19<20 && 21>20){
trace("it works");
}


Problem is probably your placement of your if statement, you need to make sure that it is either within the timeline that is moving your mc_skip or continually evaluating those values on a different timeline. Make sense?