-
Can't access array from function
Hello, I'm having trouble accessing the turnQueue array which is being updated in the first function and accessed in the second, no idea what the rules are between functions for actionscript. Heres the code, I want the turnQueue to be growing as keys are pressed, and at the moment its not updating from the first function. Thanks!
public function keyListener(e:KeyboardEvent):void {
trace("Key Entered");
if (e.keyCode > 36 && e.keyCode < 41) {
if (e.keyCode-37 != turnQueue[0]) {
turnQueue.unshift(e.keyCode-37);
}
}
}
private function move():void {
trace(turnQueue.length);
if (turnQueue.length > 0) {
dir = turnQueue.pop();
if (dir % 2 != currentDirection % 2) {
currentDirection = dir;
trace("current direction " + currentDirection);
}
}
-
If all the first function is doing is adding new elements to the array, why don't you just use push instead of unshift?
-
thats a good point actually I'm not sure i guess it doesn't really matter they still do the same thing =] But thanks for replying anyway! Managed to fix the problem!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|