Skip to main content
Participant
December 9, 2013
Question

How to make two buttons do different movements in flash?

  • December 9, 2013
  • 1 reply
  • 450 views

I am creating flash android game with as3. I created two buttons on stage with which I want to make my object move. With first button (left) I want that object would move to left and with other button (right) to right.

The problem is when I test it, output from trace shows just left pressed and left released, even thought I am pressing both buttons.  Here is my code as far as I done it:

import flash.events.Event;
import flash.events.MouseEvent;

stage
.addEventListener(MouseEvent.MOUSE_DOWN, down);
stage
.addEventListener(MouseEvent.MOUSE_UP, rel);

function down(e:MouseEvent😞void{
   
if (left) {
        trace
("left pressed");
   
} else if (right) {
        trace
("right pressed");
   
}
}

function rel(e:MouseEvent😞void{
   
if (left) {
        trace
("left released");
   
}else if (right) {
        trace
("right released");
   
}
}

Thanks for any help!!!

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
December 9, 2013

Assuming you have the variables left and right properly defined and assigned somewhere/somehow else, if you are holding down both buttons then the first condition that is true will win, which in your code is the left traces.  If you want both traces to show than you need to get rid of the else.

mind0042Author
Participant
December 9, 2013

Ok, it seems I didn't thought about simplest way to seperate things. My bad and thank you a lot to keep me on track!