Skip to main content
Participant
Nov 22, 2022 5:02 PM UTC
Question

Snipet to make items draggable in Canvas

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 is closed to new replies. Start a new post to keep the conversation going.

    5 replies

    kglad
    Community Expert
    Community Expert
    Nov 22, 2022 5:18 PM UTC

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

    Translate
    Participant
    Nov 22, 2022 5:34 PM UTC

    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

     

    Translate
    kglad
    Community Expert
    Community Expert
    Nov 22, 2022 5:41 PM UTC

    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(){

    }

    Translate