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?

1 Answer 1

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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