PDA

View Full Version : conditional statement



drakkonblade
June 22nd, 2009, 10:47 AM
i setup this conditional statement.
my intention was that if the object
foot_mc was on point0_mc then it will go to frame 5

OR

if foot_mc was on point1_mc it will go to frame 10....


function Oncheck(evt:MouseEvent):void
{
if(foot_mc == point0_mc) return;
{
gotoAndStop(5);
}
if(foot_mc == point1_mc) return;
{
gotoAndStop(10);
}
if(foot_mc == point2_mc) return;
{
gotoAndStop(15);
}
}



i get NO errors but it will always go to frame 15.... instead i want it to go to the selective frames depending on where foot_mc is...

Thank you

BoppreH
June 22nd, 2009, 10:54 AM
Coding practices aside, you are just comparing sprites, not positions. Instead of "foot_mc == point0_mc", it should be something along this lines:

foot_mc.x == point0_mc.x && foot_mc.y == point0_mc.y

But it'll only work for pixel perfect alignment, which I think is not your case. More information would be needed to correct it further.

drakkonblade
June 22nd, 2009, 11:09 AM
thank you for responding boppreh


my intention is to have the object(sprite) foot_mc to a one of the 3 coordinates which is difined already by point0..point 1....


i did successfully do the parenting... at least i hope...

but the part i am messing up on the verification of where the foot_mc is before i press the button_mc button


stop();
import flash.display.SimpleButton

var checking:Boolean = false;
point0_mc.addChild(foot_mc);
this.addEventListener(MouseEvent.MOUSE_DOWN, Onpress );
button_mc.addEventListener(MouseEvent.CLICK, Oncheck );
function Onpress(evt:MouseEvent):void {
if (evt.target == foot_mc) return;
evt.target.addChild(foot_mc);
}
function Oncheck(evt:MouseEvent):void
{
if(foot_mc == point0_mc) return;
{
gotoAndStop(5);
}
if(foot_mc == point1_mc) return;
{
gotoAndStop(10);
}
if(foot_mc == point2_mc) return;
{
gotoAndStop(15);
}
if(!checking) return;
{
gotoAndStop(5);
}
}
button_mc.buttonMode = true;


thank you

.ral:cr
June 22nd, 2009, 11:31 AM
do you have any ideea what is return doing?
it's interrupting your code to execute, but obviously is not doing that because none of the condition is true.

the code:

if(foot_mc == point2_mc) return;
{
gotoAndStop(15);
}

is equivalent with:


if(foot_mc == point2_mc) {
return;
}
gotoAndStop(15);

gotoAndStop is outside the if condition.

drakkonblade
June 22nd, 2009, 11:51 AM
i did do that and even rewrote it as that..

running into the same issue of when i press the button it always goes still to frame 15...

also oddle enough now suddenly foot_mc ... when i press the button the foot_mc graphic adds to it...