actionscript 3 - How to make an On/Off Function -
when click in stage, anywhere, calls function change 1 variables value. how make when click again changes original value?
public function example() { (...) modifier = 1; stage.addeventlistener(mouseevent.click, happening); } public function happening(event:event) { modifier = 4; }
how keeping seperate boolean variable?
var clicked:boolean = false; var modifier:int = 1; stage.addeventlistener(mouseevent.click, happening); public function happening(e:mouseevent):void{ if(clicked){ //return default modifier = 1; clicked = false; }else{ modifier = 4; clicked = true; } }
or simpler
if(modifier==4){ modifier=1; }else{ modifier=4; }
or in 1 line
modifier = (modifier==4) ? 1 : 4;
Comments
Post a Comment