canvas - How to draw a line from first mouseclick to second with easel.js -
i tried create eventlisteners drawing stage.mousey
stage.mousex
coordinates, no matter click line exact same straight down middle.
here's code
ext.onready( function(){ var g; canvas = document.getelementbyid('canvas'); var stage = new createjs.stage(canvas); function draw(a){ var mousex = stage.mousex; var mousey = stage.mousey; a.lineto(mousex, mousey); } g = new createjs.graphics(); g.setstrokestyle(1); g.beginstroke(createjs.graphics.getrgb(0,0,0)); g.beginfill(createjs.graphics.getrgb(255,0,0)); stage.addeventlistener('click', draw(g)); g.lineto(0,50); var s = new createjs.shape(g); s.x = 100; s.y = 100; stage.addchild(s); stage.update(); });
my long term goal create user created polygons selectable/highlightable way it?
this problem is:
stage.addeventlistener('click', draw(g));
it execute draw
function parameter g
. won't wait click. problem parentheses following function name, function executed immediately. need have function reference draw function. can have using anonymous function
stage.addeventlistener('click', function() {draw(g); });
Comments
Post a Comment