Chapter 5: AirRaid - Working through step-by-step
Hi all,
I'm trying to follow the AirRaid chapter of the book, and I like how it's trying to break down the bigger program in to small testable chunks. The previous game deduction kinda didn't do that and it went far too long without being able to test things.
But I have a problem.
I've set up the plane code so that I can test planes flying on to the screen, and getting deleted when they fly off without issue. But I'm trying to test the AA gun, but I can't get the code here to work. Checking the example code doesn't help here as it's final code which has way more than what I've got so far.
It's the piece of code below, where I'm not sure exactly where to put. It states in the book to put it in the Constructor Function (which I believe is in AirRaid.as), but that doesn't seem to work for me. The example has it in Airplane.as, but that doesn't work either.
// listen for keyboard
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownFunction);
stage.addEventListener(KeyboardEvent.KEY_UP,keyUpFunction);
// key pressed
public function keyDownFunction(event:KeyboardEvent) {
if (event.keyCode == 37) {
leftArrow = true;
} else if (event.keyCode == 39) {
rightArrow = true;
}
}
ERROR:
1120: Access of undefined property rightArrow.
Copyright Gary Rosenzweig
