Re: AS3 Question(s)
Blablob wrote:Also I'll mess around with the array I created later, but if you're still planning to give me more information I'd greatly appreciate that.
Sorry, but the way I was going to explain it won't work with your code (mine was with movieclips because that's the only way I've done it so far. I'm still a beginner at AS3 too :D). At the minute I'm juggling work with helping you so I haven't always got time to spend on playing with your code and seeing if I can get it working.
Switch is like an if, but you're comparing multiple values against one variable. The case is each value, and break separates them so that it doesn't continue to do the code after you've pressed one value.
- Code: Select all
switch (e.keyCode) {
case 37://left
ship.x-=10;
break;
case 38://up
ship.y-=10;
break;
case 39://right
ship.x+=10;
break;
case 40://down
ship.y+=10;
break;
}
is the same as
- Code: Select all
if (e.keyCode == 37) {
ship.x-=10;
}
if(e.keyCode == 38) {
ship.y-=10;
}
if(e.keyCode==39) {
ship.x+=10;
}
if(e.keyCode==40) {
ship.y+=10;
}
Hope that clears up switch statements. I'll work on seeing if I can get your code working.