• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Constrained movement in Animate

Explorer ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

Hello,
With Animate html5, I want myClip to be able to be moved in a Y coordinate range defined according to its starting position: here between y = 50 and y= 100 if myClip.y < 200 or between y = 300 and y = 400 if myClip.y > 200.
myClip stays at the defined coordinates but if the mouse goes beyond the Y coordinates, myClip changes zone.
Where is my error? What is the problem in my code to force myClip to never leave the predefined area?
Thanks for any answer.

this.myClip.addEventListener("mousedown", fct1.bind(this));
function fct1(evt) {
	var pm = this.globalToLocal(evt.stageX, evt.stageY);
	differenceX = (this.myClip.x - pm.x);
	differenceY = (this.myClip.y - pm.y);
};
this.myClip.on("pressmove", fct2.bind(this));
function fct2(evt) {
	var pm = this.globalToLocal(evt.stageX, evt.stageY);
	this.myClip.x = (pm.x + differenceX);
	this.myClip.y = (pm.y + differenceY);

	if (this.myClip.y < 200) {
		if (this.myClip.y > 100) {
			this.myClip.y = 100;
		}
		if (this.myClip.y < 50) {
			this.myClip.y = 50;
		}
	}
	if (this.myClip.y > 200) {
		if (this.myClip.y > 400) {
			this.myClip.y = 400;
		}
		if (this.myClip.y < 300) {
			this.myClip.y = 300;
		}
	}
};

Translated with www.DeepL.com/Translator (free version)

Views

165

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

Community Expert , Aug 20, 2021 Aug 20, 2021

use:

 

 

this.myClip.addEventListener("mousedown", fct1.bind(this));
var startPos
function fct1(evt) {
	startPos = this.globalToLocal(evt.stageX, evt.stageY);
};
this.myClip.on("pressmove", fct2.bind(this));
function fct2(evt) {
	var pm = this.globalToLocal(evt.stageX, evt.stageY);
	this.myClip.x = pm.x;
	this.myClip.y = pm.y;

	if (startPos.y < 200) {
		if (this.myClip.y > 100) {
			this.myClip.y = 100;
		}
		if (this.myClip.y < 50) {
			this.myClip.y = 50;
		}
	}
	if (startPos.y > 200) {
		if 
...

Votes

Translate

Translate
Community Expert ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

use:

 

 

this.myClip.addEventListener("mousedown", fct1.bind(this));
var startPos
function fct1(evt) {
	startPos = this.globalToLocal(evt.stageX, evt.stageY);
};
this.myClip.on("pressmove", fct2.bind(this));
function fct2(evt) {
	var pm = this.globalToLocal(evt.stageX, evt.stageY);
	this.myClip.x = pm.x;
	this.myClip.y = pm.y;

	if (startPos.y < 200) {
		if (this.myClip.y > 100) {
			this.myClip.y = 100;
		}
		if (this.myClip.y < 50) {
			this.myClip.y = 50;
		}
	}
	if (startPos.y > 200) {
		if (this.myClip.y > 400) {
			this.myClip.y = 400;
		}
		if (this.myClip.y < 300) {
			this.myClip.y = 300;
		}
	}
};

Translated with www.DeepL.com/Translator (free version)


By @mp63178988

 

Votes

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
Explorer ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

Fantastic. Many thanks to you.

Votes

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
Community Expert ,
Aug 21, 2021 Aug 21, 2021

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

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