keyboard function not reaching the array
Good afternoon,
I tried to rotate an array of objects with a mouse click, but it did not work for me, so I tried the keyboard instead, but the only way I get it to work is if I use the object name instead of the array. I get the following error message and I do not know how to fix it. Help/suggestions are appreciated.
airplane.rotation = rotationValue
Error #1010: A term is undefined and has no properties.
This is what I have:
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyboardDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyboardUp);
addEventListener(Event.ENTER_FRAME, onEnter);
var rotationSpeed:int = 0;
var rotationValue:int = 0;
var airplane:Array = [Memphis_Belle,Pitts,Spruce_Goose,Electra]
for (var i = 0; i < airplane.length; i++)
airplane.addEventListener(MouseEvent.MOUSE_DOWN, beginDrag);
function beginDrag(event:MouseEvent):void {
event.target.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, finishDrag);
function finishDrag(event:MouseEvent):void {
event.target.stopDrag();
}
function onKeyboardDown(event:KeyboardEvent):void {
if(event.keyCode == Keyboard.LEFT) {
rotationSpeed = -5;
}
if(event.keyCode == Keyboard.RIGHT)
{
rotationSpeed = 5;
}
}
function onKeyboardUp(event:KeyboardEvent):void {
if(event.keyCode == Keyboard.LEFT)
{
rotationSpeed = -0;
}
if(event.keyCode == Keyboard.RIGHT)
{
rotationSpeed = 0;
}
}
function onEnter(event:Event):void
{
rotationValue += rotationSpeed;
airplane.rotation = rotationValue;
}
