A rectangle that you can drag around.

I want to create a rectangle that I can move by clicking and dragging it. The rectangle stays in place after I stop dragging it.

Using Adobe Animate CC with html5 canvas, how can this be done?

var root = this;

var rec = root.rec;


rec.on("mousedown", function(e) { e.currentTarget.offsetX = stage.mouseX / stage.scaleX - e.currentTarget.x; e.currentTarget.offsetY = stage.mouseY / stage.scaleY - e.currentTarget.y; });

rec.on("pressmove", function(e) { e.currentTarget.x = stage.mouseX / stage.scaleX - e.currentTarget.offsetX; e.currentTarget.y = stage.mouseY / stage.scaleY - e.currentTarget.offsetY; });

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.