Skip to main content
Participant
November 22, 2022
Question

Snipet to make items draggable in Canvas

  • November 22, 2022
  • 1 reply
  • 213 views

I made a little drag and drop game in AS3 and it worked perfectly. But, you can't do anything with a swf these days. [I'm a senior.] So, now I am trying to create it with Canvas and as there is no drag and drop code available in snippets for HTML5 Canvas, I've looked at several videos, but they all use a landing spot and/or snapping and I don't want either of these. The user can drag the objects (movieclips) anywhere on the stage. Any all all help greatly appreciated.


    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    November 22, 2022

    just use the pressmove from the videos and change the pressup behavior (to not snap).

    Participant
    November 22, 2022

    I have the newest version of Animate and I don't see any options under video or other sections within Canvas that have pressmove. Can you be more specific. Thanks

     

    kglad
    Community Expert
    Community Expert
    November 22, 2022

    this.b.addEventListener("pressmove",moveF.bind(this));
    this.b.addEventListener("pressup", upF.bind(this));

    function moveF(e){
    e.currentTarget.x = e.stageX;
    e.currentTarget.y = e.stageY;
    }
    function upF(){

    }