2015-04-23 42 views
0

我知道我错过了一些非常简单的东西,但我似乎无法弄清楚。所以,我有我的按钮,控制舞台上的日志,像这样:ENTER_FRAME事件不能正常使用MouseEvent As3

//buttons for main screen left and right 
     mainScreen.leftBtn.addEventListener(MouseEvent.CLICK, leftButtonClicked); 
     mainScreen.rightBtn.addEventListener(MouseEvent.CLICK, rightButtonClicked); 

private function leftButtonClicked(e:MouseEvent):void 
    { 
     if (e.type == MouseEvent.CLICK) 
     { 
      clickLeft = true; 
      trace("LEFT_TRUE"); 
     } 
    } 

    private function rightButtonClicked(e:MouseEvent):void 
    { 
     if (e.type == MouseEvent.CLICK) 
     { 
      clickRight = true; 
      trace("RIGHT_TRUE"); 
     } 
    } 

现在这些控制日志旋转,我已经安装在称为logControls();像这样一个ENTER_FRAME事件监听功能:

private function logControls():void 
    { 


     if (clickRight) 
     { 

      log.rotation += 20; 

     }else 
     if (clickLeft) 
     { 
      log.rotation -= 20; 

     } 
    } 

我想要做的是当用户向左或向右按​​下日志左右旋转每个框架。但是,发生的事情是它只能以一种方式旋转,并且不会响应其他鼠标事件。我可能做错了什么?

+0

无需检查('e.type == MouseEvent.CLICK') - 你会得到一个运行时错误,如果不是这样。你可能只需要设置你的'clickLeft'和'clickRight'变量为false时,当相反的设置或鼠标上。 – BadFeelingAboutThis

回答

1

可能你只需要在设置旋转时将var设置为false。所以如果你左旋转,你想把clickRight var设置为false。

mainScreen.leftBtn.addEventListener(MouseEvent.CLICK, rotationBtnClicked); 
mainScreen.rightBtn.addEventListener(MouseEvent.CLICK, rotationBtnClicked); 

private function rotationBtnClicked(e:MouseEvent):void { 
    clickLeft = e.currentTarget == mainScreen.leftBtn; //if it was left button clicked, this will true, otherwise false 
    clickRight = e.currentTarge == mainScreen.rightBtn; //if it wasn't right button, this will now be false 
} 

private function logControls():void { 
    if (clickRight){ 
     log.rotation += 20; 
    } 

    if (clickLeft){ 
     log.rotation -= 20; 
    } 
} 
+0

由于LDMS这工作完美。我试图做到这一点完全相同的东西,但在logControl函数内,所以它仍然无法正常工作。没想到添加到鼠标事件会修复它哈哈。再次感谢! – Nathan

+0

这就是相同的方法,但只是更清洁? – Nathan

+0

是的,少用这种方式的代码。 – BadFeelingAboutThis