actionscript 3 - verifying a IF condition always AS3 -
i'm beginner in as3 please if possible give point noob answer. want have specific button clicked create line, example click button need click twice on stage
- i click , selected
- i click first time on stage select starting point of line
- i click second time on stage select finishing point.
i tried can`t manage to, if possible please me. code wrote
dr_line.addeventlistener(mouseevent.click,drawln); var test:boolean; function drawln(e:mouseevent):void{ test=true; stage.addeventlistener(mouseevent.click,reportclick); } var sx,sy,fx,fy:int; var j:int; function reportclick(event:mouseevent):void { j=0; j++; if (test==true && j==1) { sx=event.localx; sy=event.localy; } j++; test=true; trace(j); trace(test); if (test==true && j==2) { fx=event.localx; fy=event.localy; j=0; test=false; var line:shape = new shape(); line.graphics.beginfill(0x00ff00); line.graphics.moveto(sx,sy); line.graphics.lineto(fx,fy); this.addchild(line); } }
how should make work .. please me , !!!! ,and yes function reportclick should checked .... can`t going or when press dr_line button should active checked ....
you assigning j=0 in click handler... should in drawln instead. also, require 1 j++ in click handler.
but cleaner approach have 2 click listener point1clicklistener
, point2clicklistener
. should attach point1clicklistener
in drawln
. inside point1clicklistener
remove listening clicks point1clicklistener
, attach click listener point2clicklistener
. again, when point2clicklistener
gets called remove listening clicks point2clicklistner
.
Comments
Post a Comment