开发者

Mouse Move fires Mouse Click (Adobe Air)

开发者 https://www.devze.com 2023-04-12 10:41 出处:网络
I am trying to have two guestures on a SpriteVisualElement which I thought should be pretty simple implemented:

I am trying to have two guestures on a SpriteVisualElement which I thought should be pretty simple implemented:

Mouse_Move for sweep Gestures and mouse click to enable..

So I have 2 Eventlisteners on my stage:

stage.addEventListener(MouseEvent.CLICK, taphandler);
stage.addEventListener(MouseEvent.MOUSE_DOWN, mousedownhandler);

The main problem is that every type of sweeping on the screen also fires the taphandler()..

Any ideas on how to identify the correct event?

I tried to to my taphandler only if(!eve开发者_运维知识库nt.buttondown) but no success.


Do you need to handle MouseEvent.CLICK specifically? Or are you just trying to handle a tap and a drag separately. If this is the case, try one of these two for a tap:

MySprite.addEventListener(TouchEvent.TOUCH_TAP, taphandler);
MySprite.addEventListener(PressAndTapGestureEvent.GESTURE_PRESS_AND_TAP, taphandler);

(note that these event handlers are on your sprite, and not the stage)

For touch and drag, try:

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

MySprite.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
MySprite.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
MySprite.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);

function onTouchBegin(eBegin:TouchEvent) {
     eBegin.target.startTouchDrag(eBegin.touchPointID, false, bg.getRect(this));
     trace("touch begin");

 }

function onTouchMove(eMove:TouchEvent) {
    trace(eMove.stageX);
}

function onTouchEnd(eEnd:TouchEvent) {
     eEnd.target.stopTouchDrag(eEnd.touchPointID);
     trace("touch end");
}

The only issue you may run into is that TouchEvent.TOUCH_TAP and TouchEvent.TOUCH_BEGIN both might be interpreted as MouseClick.TOUCH on your device, so if you have a handler attached to your sprite for MouseClick.TOUCH, you will have a conflict.

BTW, most of this info is from the Adobe Actionscript 3.0 Reference - TouchEvent

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号