Quick background:
I am part of a small team making a game in flash. My specific role is in the audio department, but I do have to take time in helping with the scripting. Now I’ve managed to do a few things on my own, such as the audio integration and having the enemy ai patrol, but I’ve been trying to do another small piece that seems beyond my ability, so I joined here to get some help.
Basically, the game has two characters that the player can control, but they only control one at a time. What I’ve been trying to do is write the controls for one character (KeyboardEvent.KEY_DOWN) and place them on the arrow keys, and then place a control that switches to the second character on the Enter key, at which point the first character should not be able to move.
Again, please understand that I’m not a programmer and so this will look pretty damn pathetic and is probably suffering from som hugely obvious (well, to all of you, not me) oversight. I’m the audio guy, but programming needs some help from me… and therefore I need some help from you.
var character = character
//Making a character move
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
function keyHandler(e:KeyboardEvent)
{
if (e.keyCode == Keyboard.LEFT)
{
character.x -= 10;
}
if (e.keyCode == Keyboard.RIGHT)
{
character.x += 10;
}
if (e.keyCode == Keyboard.UP)
{
character.y -= 10;
}
if (e.keyCode == Keyboard.DOWN)
{
character.y += 10;
}
}
//Switching Active Character
stage.addEventListener(KeyboardEvent.KEY_DOWN, switching);
function switching(e:KeyboardEvent)
{
if (e.keyCode == 13)
{
if (character == wally_mc)
{
character == joe_mc
}
if (character == joe_mc)
{
character == wally_mc
}
}
}
TypeError: Error #1010: A term is undefined and has no properties.
at switching1_fla::MainTimeline/keyHandler()
Yeah, it’s pathetic…