Skip to main content
Gh0strom
Participating Frequently
January 5, 2012
Question

Problem with variables.

  • January 5, 2012
  • 1 reply
  • 539 views

Hi,

I was trying to use arrows keys for navigation. I got 12 frames to be navigated. So thought up the following code.

var position=0;

stage.addEventListener(KeyboardEvent.KEY_UP, moveRight);

function moveRight(e:KeyboardEvent):void {

    switch (e.keyCode) {

    case Keyboard.LEFT :

    if(position>0)

    {  

        prevFrame();

        position--;

        trace(position);

    }

    break;

    case Keyboard.RIGHT :

    if(position<=12)

    {

        nextFrame();

        position++;

        trace(position);

    }

    break;

}

==================================

The problem is :

If I  press a right , position = 1, then if i click a left position becomes -1. why ?

Plz help.

This topic has been closed for replies.

1 reply

Known Participant
January 5, 2012

Hi

Please use the code :

if(position>1)

Gh0strom
Gh0stromAuthor
Participating Frequently
January 6, 2012

It was simple problem.

I had to declare position outside this frame. thanks for replys.