A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Can't access array from function

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    25

    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);
    }
    }

  2. #2
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    If all the first function is doing is adding new elements to the array, why don't you just use push instead of unshift?

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    25
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center