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

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -