Skip to main content
MarkSmit
Inspiring
October 13, 2022
Answered

Pressmove event not working with if else statement

  • October 13, 2022
  • 1 reply
  • 675 views

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;
	}
}

 

 

This topic has been closed for replies.
Correct answer Vladin M. Mitov

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


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;
}

 

 

1 reply

Vladin M. Mitov
Inspiring
October 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 1998Member of Flanimate Power Tools team - extensions for character animation
MarkSmit
MarkSmitAuthor
Inspiring
October 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();
}
Vladin M. Mitov
Inspiring
October 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 1998Member of Flanimate Power Tools team - extensions for character animation