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

Play backwards when scrolling up

Explorer ,
May 10, 2021 May 10, 2021

Copy link to clipboard

Copied

Hello guys,

I was wondering if it is possible to make the animation play backwards when I scroll up.

As you see the last part of the code doesn't make any sense.

If anyone knows how to make the animation play backwards when wheelDelta>=0 it would really help me out. 

Thanks in advance

 

var f=this;
stage.enableMouseOver();
stage.addEventListener("mouseover", h);
function h() {
	document.getElementById('canvas').addEventListener('mousewheel', k);
}
function k(e) {
	if (e.wheelDelta < 0) {
		if (f.pock.currentFrame == 145) {
			f.pock.gotoAndStop(145);
		} else {
			f.pock.play();
		}
	}
	if (e.wheelDelta >= 0) {
		if (f.pock.currentFrame == 0) {
			f.pock.gotoAndStop(0);
		} else {
			f.pock.playReverse();
		}
	}
}

 

Views

697

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 ,
May 10, 2021 May 10, 2021

Copy link to clipboard

Copied

in general, it's a bad idea to add code (other than play(), stop() etc) in non-main timelines.

 

that said, you can add code to other timelines as indicated in that code.  ie, playReverse() is (supposed to be) on the f>pock timeline.  did you look there?

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 ,
May 10, 2021 May 10, 2021

Copy link to clipboard

Copied

Thanks for the answer kglad. 

What do you mean with f>pock timeline? 

Anyway, I converted the level with the animation in a symbol, then in the main timeline I added an actions layer.

My problem here is that I don't know how to make the animation play backwards while scrolling up.... I didn't really fully understand what you meant with your message

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 ,
May 10, 2021 May 10, 2021

Copy link to clipboard

Copied

you must use a loop:

 

var loop = loopF.bind(this);

this.addEventListener("enterframe",loop);

function loopF(){

this.yourbackplayingmc.gotoAndStop(this.yourbackplayingmc.currentFrame-1);

if(this.yourbackplayingmc.currentFrame==0){

this.removeEventListener("enterframe",loop);

}

}

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 ,
May 10, 2021 May 10, 2021

Copy link to clipboard

Copied

Doesn't work... would it help if I share the project file? Or the whole code if you prefer, the one in the first message is just the part regarding the scroll

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 ,
May 10, 2021 May 10, 2021

Copy link to clipboard

Copied

that's more than i do free of charge.  if you want to hire me, send a private message.  otherwise, show the code you used from the code i suggested.

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 ,
May 11, 2021 May 11, 2021

Copy link to clipboard

Copied

If I understood correctly, the code you suggested make the timeline go backwards by one frame every roll of the mouse. That's not what I need. The code in my first message make the animation play when I trigger the mousewheel, I need the same thing but the animation should play backwards when I scroll up. Note that it will automatically stop when It has to as I added "this.stop();" in the animation timeline. 

var loop = loopF.bind(f);
	f.addEventListener("enterframe", loop);
	function loopF() {
		f.pock.gotoAndStop(f.pock.currentFrame - 1);
		if (f.pock.currentFrame == 0) {
			f.removeEventListener("enterframe", loop);
		}
	}

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 ,
May 11, 2021 May 11, 2021

Copy link to clipboard

Copied

the code is suggested doesn't do anything because there's no "enterframe" event in createjs.  everything else is correct and you misunderstand (what) the code (should do).

 

var loop = loopF.bind(this);

createjs.Ticker.addEventListener("tick",loop);


function loopF(){

this.mc.gotoAndStop(this.mc.currentFrame-1);

if(this.mc.currentFrame==0){

createjs.Ticker.removeEventListener("tick",loop);

}

}

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 ,
May 11, 2021 May 11, 2021

Copy link to clipboard

Copied

It doesn't work. No worries, I'll contact a programmer and see what he'll come up with. Thanks anyway, have a nice day

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 ,
May 11, 2021 May 11, 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