ActionScript 3 Repeated clicks slows down the program -



ActionScript 3 Repeated clicks slows down the program -

so i've got number of frames, , in 1 frame have movieclip next code: adds shape draw biological cells alter colour when particular movieclip called 'test' pressed. 'morphogen1',... other movieclips can dragged around.

cells = new shape() this.addchild(cells) this.setchildindex(cells,1) function drawcell(xx,yy){ if(logic(xx,yy)){col=0xff4444}else{col=0xffbbbb} with(cells.graphics){ beginfill(col) drawcircle(xx,yy,5) endfill() } } function drawcells(){ for(i=0;i<=15;i++){ for(j=0;j<=10;j++){ drawcell(i*22,j*14) } } } function dist(x1,y1,x2,y2){ homecoming math.exp(-((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))/50000) } function logic(xx,yy){ va = dist(xx,yy,morphogen1.x,morphogen1.y) vb = dist(xx,yy,morphogen2.x,morphogen2.y) vc = dist(xx,yy,morphogen3.x,morphogen3.y) if(ctrl==1){sa=(va>0.5)}else{sa=(va<vb)} homecoming sa&&(vb>0.5)&&(vc>0.5) } test.addeventlistener(mouseevent.click, swap) function swap(e:mouseevent){ ctrl = 1-ctrl drawcells() }

it works intended, more 'test' clicked, more programme slows down; 30 clicks lag noticeable.

i amateur programmer - i've committed major nono; event listener clogging cpu? i've tried removing math.exp function much simpler, same problem.

to activate hardware acceleration swf file, go file > publish settings... or ctrl (win) / cmd (mac) + shift + f12, window , @ bottom select hardware acceleration :

actionscript-3

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -