Highlighted

Instance "jumps" to mouse position

Explorer ,
Jul 26, 2020

Copy link to clipboard

Copied

Hello, guys!
I would like to know how to correct the code to prevent "jump" of instance (Y coords) to initial Mouse Down position. What should I add?

 

this.L.y = 430;
this.L.on("pressmove", function(evt) {
   let p = evt.currentTarget.parent.globalToLocal(evt.stageX, evt.stageY);
   //evt.currentTarget.x = p.x;
   evt.currentTarget.y = p.y;
   if (evt.currentTarget.y > 730) {
      evt.currentTarget.y = 730;
   } else if (evt.currentTarget.y < 430) {
      evt.currentTarget.y = 430;
   }
stage.update();
});

 

Thank you!

TOPICS
Code

Views

74

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

Instance "jumps" to mouse position

Explorer ,
Jul 26, 2020

Copy link to clipboard

Copied

Hello, guys!
I would like to know how to correct the code to prevent "jump" of instance (Y coords) to initial Mouse Down position. What should I add?

 

this.L.y = 430;
this.L.on("pressmove", function(evt) {
   let p = evt.currentTarget.parent.globalToLocal(evt.stageX, evt.stageY);
   //evt.currentTarget.x = p.x;
   evt.currentTarget.y = p.y;
   if (evt.currentTarget.y > 730) {
      evt.currentTarget.y = 730;
   } else if (evt.currentTarget.y < 430) {
      evt.currentTarget.y = 430;
   }
stage.update();
});

 

Thank you!

TOPICS
Code

Views

75

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
Jul 26, 2020 0
Adobe Community Professional ,
Jul 26, 2020

Copy link to clipboard

Copied

Capture the X/Y difference between the mouse coordinates and the clicked symbol to a set of persistent variables, then subtract (or add) that difference when setting the symbol's dragged coordinates.

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
Reply
Loading...
Jul 26, 2020 0
Explorer ,
Jul 26, 2020

Copy link to clipboard

Copied

Sure, I have done this with mouseclick. Then mouse down. How to do this within one code block?

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
Reply
Loading...
Jul 26, 2020 0
Explorer ,
Jul 28, 2020

Copy link to clipboard

Copied

Снимок экрана 2020-07-28 в 16.55.06.png

 

Bu the way, can you help me to understand how to put 'INCORRECT' movie clip straight to mouse coordinates? There are main window and inner movie clip. I want to get this "INCORRECT" opened only while click at panel_PA_anim with right coordinates.

 

this.panel_PA_anim.addEventListener("click", (e) => {
Object(this.parent).incorrect.x = this.panel_PA_anim.x + stage.mouseX;
Object(this.parent).incorrect.y = this.panel_PA_anim.y + stage.mouseY;
Object(this.parent).incorrect.visible = true;
});

 

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
Reply
Loading...
Jul 28, 2020 0
Explorer ,
Jul 26, 2020

Copy link to clipboard

Copied

I've fixed the problem in a such way. It works perfectly on iMac, but then doesn't work on iPad.

What's the problem?

 

createjs.Touch.enable(stage);

this.L.y = 430;
let offset = 0;

 

this.L.addEventListener("mousedown", (evt) => {
let a = evt.currentTarget.parent.globalToLocal(evt.stageX, evt.stageY);
offset = a.y - evt.currentTarget.y;
console.log('mouse clicked');
});

this.L.addEventListener("pressmove", (evt) => {
let p = evt.currentTarget.parent.globalToLocal(evt.stageX, evt.stageY);
//evt.currentTarget.x = p.x;
evt.currentTarget.y = p.y - offset;
if (evt.currentTarget.y > 730) {
evt.currentTarget.y = 730;
} else if (evt.currentTarget.y < 430) {
evt.currentTarget.y = 430;
}
stage.update();
});

this.L.addEventListener("touchstart",function(evt) {
evt.preventDefafult();
let a = evt.currentTarget.parent.globalToLocal(evt.stageX, evt.stageY);
offset = a.y - evt.currentTarget.y;
console.log('touched');
});

this.L.addEventListener("touchmove",function(evt) {
evt.preventDefafult();
let p = evt.currentTarget.parent.globalToLocal(evt.stageX, evt.stageY);
//evt.currentTarget.x = p.x;
evt.currentTarget.y = p.y - offset;
if (evt.currentTarget.y > 730) {
evt.currentTarget.y = 730;
} else if (evt.currentTarget.y < 430) {
evt.currentTarget.y = 430;
}
stage.update();
});

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
Reply
Loading...
Jul 26, 2020 0
Adobe Community Professional ,
Jul 27, 2020

Copy link to clipboard

Copied

"Doesn't work" is uselessly vague. What exactly do you mean?

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
Reply
Loading...
Jul 27, 2020 0