ENTER_FRAME 事件无法与 MouseEvent As3 一起正常工作
ENTER_FRAME Event not working correctly with 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;
}
}
我想要做的是当用户向左或向右按下时日志向左或向右旋转每一帧。但是发生的事情是它只以一种方式旋转并且不响应其他鼠标事件。我可能做错了什么?
您可能只需要在设置旋转时将 opposite var 设置为 false 即可。因此,如果您向左旋转,则需要将 clickRight 变量设置为 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;
}
}
我知道我遗漏了一些非常简单的东西,但我似乎无法弄明白。所以我有我的按钮来控制舞台上的日志,如下所示:
//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;
}
}
我想要做的是当用户向左或向右按下时日志向左或向右旋转每一帧。但是发生的事情是它只以一种方式旋转并且不响应其他鼠标事件。我可能做错了什么?
您可能只需要在设置旋转时将 opposite var 设置为 false 即可。因此,如果您向左旋转,则需要将 clickRight 变量设置为 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;
}
}