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

Pressmove event not working with if else statement

Participant ,
Oct 13, 2022 Oct 13, 2022

I made a switch button (first click: shape1_animation plays, second click: shape2_animation plays) in Adobe Animate. It works fine with the "click" event. But it doesn't work with the "pressmove" event and I wonder why.

 

Projectfile:

https://www.dropbox.com/s/2mh8fxah9o7a7qk/play_movieclip%2005.fla?dl=0

 

When I "pressmove" the button, the two animations play simultaneously. So it completely ignores the if else statements

 

Maybe there is a simple awnser to this?

 

this.button.addEventListener("pressmove", onPressMove.bind(this));
let counter = 0;

function onPressMove() {
	if (counter == 0) {
		this.shape1_animation.play();
		counter=1;
	} else {
		this.shape2_animation.play();
		counter=0;
	}
}

 

 

TOPICS
Code
579
Translate
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

Engaged , Oct 13, 2022 Oct 13, 2022

I suppose you want to run the animation (shape1_animation) and at the same time - to drag the button.
Maybe something like this would work...

 

let counter = 0;

this.button.addEventListener("click", onClick.bind(this));
this.button.addEventListener("pressmove", onPressMove.bind(this));

function onClick( evt ) {
   evt.currentTarget.offset = { x: evt.stageX / stage.scaleX - evt.currentTarget.x, y: evt.stageY / stage.scaleY - evt.currentTarget.y };	
	if (counter == 0) {
		this.shape1_animation.play
...
Translate
Engaged ,
Oct 13, 2022 Oct 13, 2022

Hi,

My guess is, because the mouse dragging generates multiple "pressmove" events and the variable counter sequentially switches between 0 and 1.
Add a trace() statement to see what is actually happening.

 

 

- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation
Translate
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
Participant ,
Oct 13, 2022 Oct 13, 2022

Hi Vlad,

 

I added a console.trace(); if you meant that. The result does not say much to me.

this.button.addEventListener("pressmove", onPressMove.bind(this));
let counter = 0;

function onPressMove() {
	if (counter == 0) {
		this.shape1_animation.play();
		counter=1;
	} else {
		this.shape2_animation.play();
		counter=0;
	}
	console.trace();
}
Translate
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
Engaged ,
Oct 13, 2022 Oct 13, 2022

Sorry, my mistake...

Just add a statement to help you to observe how many times the event is fired and what is the value of counter.

console.log( counter );

 

 

- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation
Translate
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
Participant ,
Oct 13, 2022 Oct 13, 2022

I think you are right. When ik click and drag it ones, this entire list pops up. Is there a way to fix this?

Translate
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
Engaged ,
Oct 13, 2022 Oct 13, 2022
LATEST

I suppose you want to run the animation (shape1_animation) and at the same time - to drag the button.
Maybe something like this would work...

 

let counter = 0;

this.button.addEventListener("click", onClick.bind(this));
this.button.addEventListener("pressmove", onPressMove.bind(this));

function onClick( evt ) {
   evt.currentTarget.offset = { x: evt.stageX / stage.scaleX - evt.currentTarget.x, y: evt.stageY / stage.scaleY - evt.currentTarget.y };	
	if (counter == 0) {
		this.shape1_animation.play();
		counter=1;
	} else {
		this.shape2_animation.play();
		counter=0;
	}
}

function onPressMove( evt ){
	evt.currentTarget.x = evt.stageX / stage.scaleX - evt.currentTarget.offset.x;
	evt.currentTarget.y = evt.stageY / stage.scaleY - evt.currentTarget.offset.y;
}

 

 

- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation
Translate
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