Skip to main content
Known Participant
March 21, 2016
Question

mouse event does not seem to have effect

  • March 21, 2016
  • 3 replies
  • 819 views

hi, I am making a game that uses a virtual joystick. In the pc it works fine, but there is a problem testing in the pc as the pc does not have a touch screen, so mouse down is not the same in the pc as the touch screen (for example)

the thing is, recently I started debugging it in an android device. It works fine except for one thing: when the user lifts the finger, the joystick is supposed to reset itself (working as an autocenter). Instead, the joystick remains in the last position of the finger, without centering itself.

The same handler is linked to the joystick object, and it works fine in the 'mouse_out' event, but not when the finger is lifted. I tried moving from 'joystick.addEventListener' to stage.addEventListener, though it should not make a difference, since to lift the finger outside the joystick first it would have had to be moved out, but I did it anyway. The handler does not contain any guard as ''if (event.target != event.currentTarget)" or something like that. once again, the code in the handler is fine, as it works in the move out event; also, I use similar handlers for the stage in different frames (and remove those when exiting the frame), and those work fine.

Any pointers as to why the handler does not work when lifting the finger, neither linked to the joystick or stage objects, yet similar handlers work in stage in different frames, or the same handler works as a move out from the joystick?

tnx

edit, to clear out: when I drag or slide the finger outside the joystick area, it autocenters (the 'move out' handler is called), but when I lift the finger, the joystick remains in the same position it had before lifting the finger, till I touch somewhere else in the screen

This topic has been closed for replies.

3 replies

Known Participant
March 24, 2016

problem finally solved (for now). it seems when I lift my finger, it does not only triggers a mouse up event, but a mouse move as well, and the move handler was undoing the up handler

Known Participant
March 22, 2016

update, the weirdest thing:

function joystick_deactivate(event:MouseEvent):void {

    joystick_active = false; // there is something in enterframe that if joystick is not active, it will center it

    joystick.gotoAndStop(1); // the frame that shows the joystick as not being touched

    background.nextFrame(); // not part of the final handler, but added as control to view any effect of the handler

    if (background.currentFrame == background.totalFrames)

        background.gotoAndStop(1);

}

joystick.addEventListener(MouseEvent.MOUSE_OUT, joystick_deactivate);

joystick.addEventListener(MouseEvent.MOUSE_UP, joystick_deactivate);

now, there is a weird behavior, for which I have no explanation: if I slide the finger out of the joystick area (mouse out), it will autocenter, but the background will not change, as if it executed the first two lines of the handler, but not the rest. If I lift my finger, it will change background (the control sentence), but will not autocenter. Is like if each event called the handler, but executed only one part of it..?

kglad
Community Expert
Community Expert
March 23, 2016

again, you can use mousedown, but otherwise mouse events for touch devices don't work well.  use touch events.

kglad
Community Expert
Community Expert
March 22, 2016

you can use mousedown, but otherwise mouse events for touch devices don't work well.  use touch events.

Known Participant
March 22, 2016

tnx, but then I would not be able to test it with the pc. The thing is, 'stage' has handlers for that same event in other frames (mouse up), and they work fine. But in this frame, neither linking the handler to the stage, or the joystick, does it work. Is there any reason that prevents an event from being triggered?

kglad
Community Expert
Community Expert
March 22, 2016

use conditional compiling to easily handle diffierent test/production environments.