strange movie clip behavior on drag

Contributor ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

Hi, I am trying to implement drag and drop in Animate Canvas, using JavaScript.  I am using the code below to grab a movie clip and move it around.  The mouse does grab the clip and move it, but as I drag towards the lower right of the stage, the mouse pointer gets farther and farther away from the movie clip (see JPG).  Here's my code.  Is there a fix for this?  Thanks.

Zaffer

this.blueBall_1.on("pressmove", moveBlueBall);

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

 drag drop anomaly.jpg

TOPICS
Code , How to

Views

46

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Feb 21, 2022 Feb 21, 2022
Thanks Niktendo,It's not a problem with registration.  Its a problem with globalToLocal.  You have to set the main timeline (exportRoot) global coordinates to local coordinates.  This code makes dragging the blue ball work perfectly:let blueBall = this.blueBall_1; let pt; blueBall.addEventListener("pressmove", moveBlueBall.bind(this)); function moveBlueBall(e){ blueBall = e.currentTarget; pt = exportRoot.globalToLocal(e.stageX, e.stageY); e.currentTarget.x = pt.x; e.currentTarget.y = pt.y;...

Likes

Translate

Translate
Adobe Community Professional ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

 Make sure your registration point is in the middle of the ball.

 

Screen Shot 2022-02-21 at 6.34.27 PM.png


Multimedia Developer, Character Creator, and Animator.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

LATEST

Thanks Niktendo,

It's not a problem with registration.  Its a problem with globalToLocal.  You have to set the main timeline (exportRoot) global coordinates to local coordinates.  This code makes dragging the blue ball work perfectly:

let blueBall = this.blueBall_1;
let pt;

blueBall.addEventListener("pressmove", moveBlueBall.bind(this));

function moveBlueBall(e){
	blueBall = e.currentTarget;
	pt = exportRoot.globalToLocal(e.stageX, e.stageY);
	e.currentTarget.x = pt.x;
	e.currentTarget.y = pt.y;
}

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines