actionscript 3 - ENTER_FRAME Event not working correctly with MouseEvent As3 -
i know missing simple can't seem figure out. have buttons control log on stage so:
//buttons main screen left , 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"); } }
now these control logs rotation have setup in enter_frame event listener function called logcontrols();
so:
private function logcontrols():void { if (clickright) { log.rotation += 20; }else if (clickleft) { log.rotation -= 20; } }
what want when user presses left or right log rotates each frame left or right. happening rotates 1 way , doesnt respond other mouse events. doing wrong?
likely need set opposite var false when set rotation. if you're rotating left, want set 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 left button clicked, true, otherwise false clickright = e.currenttarge == mainscreen.rightbtn; //if wasn't right button, false }
private function logcontrols():void { if (clickright){ log.rotation += 20; } if (clickleft){ log.rotation -= 20; } }