Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How can I have 2 variables for one output?

New Here ,
Jan 29, 2014 Jan 29, 2014

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

}


TOPICS
ActionScript
304
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 30, 2014 Jan 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

           

        }

       

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 30, 2014 Jan 30, 2014
LATEST

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;

 

                    }

          }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines