Skip to main content
Participant
January 30, 2014
Question

How can I have 2 variables for one output?

  • January 30, 2014
  • 1 reply
  • 328 views

I need it so that the spacebar does one thing on one frame and another thing on the other.

I have solved this but now I need to know how can I have it so 2 variables = 1 output.

This is my code at the moment:


while (menu)

if (changecharacter)

{


gotoAndStop(2);


menu = false

}


This topic has been closed for replies.

1 reply

Inspiring
January 30, 2014

I need it so that the spacebar does one thing on one frame and another thing on the other.

your code doesn`t show how you catch the Spacebar input.

KeyboardListeners should always be attached to the stage

stage.addEventListener(KeyboardEvent.KEY_UP, myKeyUp);

function myKeyUp(e:KeyboardEvent):void

{

   

    if (e.keyCode == Keyboard.SPACE)

    {

       

        var condition1:Boolean;

       

        var condition2:Boolean;

       

        if (condition1)

        {

           

                //do sth.

           

        }

       

        else if (condition2)

        {

           

                //do sth.else

           

        }

       

    }

}

Participant
January 30, 2014

My whole code is:

var menu:Boolean = true

stop();

var leftPressed:Boolean = false;

var rightPressed:Boolean = false;

var changecharacter:Boolean = false;

Block.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey);

stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed);

stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed);

Block.gotoAndStop(1)

function fl_MoveInDirectionOfKey(event:Event)

{

 

          if (leftPressed)

          {

                    Block.x -= 3;

          }

          if (rightPressed)

          {

                    Block.x += 3;

          }

          if (changecharacter)

          {

                    Block.gotoAndStop(2);

          }

          while (menu)

          if (changecharacter)

          {

                    gotoAndStop(2);

                    menu = false

          }

 

}

function fl_SetKeyPressed(event:KeyboardEvent):void

{

          switch (event.keyCode)

          {

 

                    case Keyboard.LEFT:

                    {

                              leftPressed = true;

                              break;

                    }

                    case Keyboard.RIGHT:

                    {

                              rightPressed = true;

                              break;

                    }

                    case Keyboard.SPACE:

                    {

                              changecharacter = true;

                              break;

                    }

          }

}

function fl_UnsetKeyPressed(event:KeyboardEvent):void

{

          switch (event.keyCode)

          {

 

                    case Keyboard.LEFT:

                    {

                              leftPressed = false;

                              break;

                    }

                    case Keyboard.RIGHT:

                    {

                              rightPressed = false;

                              break;

                    }

                    case Keyboard.SPACE:

                    {

                              changecharacter = false;

                              break;

 

                    }

          }

}