PDA

View Full Version : Move object and switch(case) the x value of object.



descalabro
February 23rd, 2009, 11:11 AM
What I'm trying to do here is capture and use the x coordinate of my dummy_MC to gotoAndPlay the correct movement animation.



case Key.RIGHT :
switch (_global.posture) {
case 1 :
dummyorient = "right";
_root.dummy_MC._x += speed;
switch (_root.dummy_MC._x) {
case "<450" :
trace("< 450");
_root.dummy_MC.gotoAndPlay("frame case 450");
break;
case "> 449 && < 550" :
trace("> 449 && < 550");
_root.dummy_MC.gotoAndPlay("frame case 449 550");
break;
case "> 549" :
trace("> 549");
_root.dummy_MC.gotoAndPlay("frame case 549");
break;
}
break;


The rest of the code is working, the dummy_MC moves correctly.

This, however, isn't working, neither if I use:



case (<450) :


What's the way to do this using a switch action?
Logic tells me swtich actions are able to answer any possible condition, just like using IF, so the problem must be the syntax.

Thank you for reading.

cbeech
February 27th, 2009, 11:30 AM
well you can't really use a switch in the way you are trying to here, you need to use a if/elseif/else condition to determine if the value falls within the range specified. additionally, the case values you have are datatyped as Strings - not a numeric values, so they will never match the condition in the switch.

descalabro
February 27th, 2009, 07:59 PM
I see. I asked to be sure this couldn't be done using a switch, because the code would be more simple that way. But now it makes sense: I can't have a specific case testing for such a wide range of values.

Thank you.

cbeech
February 28th, 2009, 12:18 AM
you're welcome :)