Copy link to clipboard
Copied
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;
}
}
1 Correct answer
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
...
Copy link to clipboard
Copied
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.
Member of Flanimate Power Tools team - extensions for character animation
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
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 );
Member of Flanimate Power Tools team - extensions for character animation
Copy link to clipboard
Copied
I think you are right. When ik click and drag it ones, this entire list pops up. Is there a way to fix this?
Copy link to clipboard
Copied
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;
}
Member of Flanimate Power Tools team - extensions for character animation

