//setup Listeners when btn's are rolled over and out
btnUp.addEventListener(TouchEvent.TOUCH_OVER, btnUpMouseOver, false, 0, true);
btnUp.addEventListener(TouchEvent.TOUCH_OUT, btnUpMouseOver, false, 0, true);
btnDown.addEventListener(TouchEvent.TOUCH_OVER, btnDownMouseOver, false, 0, true);
btnDown.addEventListener(TouchEvent.TOUCH_OUT, btnDownMouseOver, false, 0, true);
shootPlayer.addEventListener(TouchEvent.TOUCH_TAP, shootPlayerObject, false, 0, true);
我有这些功能:
private function btnDownMouseOver(e:TouchEvent):void
{
//trace("btnDownRollover");
if (e.type == TouchEvent.TOUCH_OVER)
{
//Mouse was pressed on this button
btnPressedDown = true;
}
else
{
//Mouse was released
btnPressedDown = false;
}
}
private function btnUpMouseOver(e:TouchEvent):void
{
//trace("btnUpRollOver");
if (e.type == TouchEvent.TOUCH_OVER)
{
//Mouse was pressed on this button
btnPressedUp = true;
}
else
{
//Mouse was released
btnPressedUp = false;
}
}
这就是现在控制船只的东西。如上所述,它工作正常。只是想看看他们是否有任何方法可以摆脱按钮,只要手指改变方向就让它在向上或向下位置做出反应。任何帮助将不胜感激,谢谢!
答案 0 :(得分:1)
不要在对象上添加mouseUp / TouchOut侦听器,而是在mouseDown / TouchOver处理程序内的舞台上侦听它们。像这样:
private function btnDownMouseOver(e:TouchEvent):void
{
//you may need to do something with e.touchPointID if using multi-touch
//Mouse was pressed on this button
btnPressedDown = true;
stage.addEventListener(TouchEvent.TOUCH_OUT, btnOut); //now that the mouse is down, lets listen for the up event globally
}
private function btnOut(e:TouchEvent):void
{
//Mouse was released
btnPressedDown = false;
stage.removeEventListener(TouchEvent.TOUCH_OUT,btnOut); //now the up event has fired, let's stop listening for it globally.
}
}
通过触摸(如果支持多点触控),您还需要跟踪touchPointID
TouchEvent
,否则即使您只松开一根手指,touchOut也会触发所有触摸点。< / p>