Skip to main content
Inspiring
May 10, 2021
Question

Play backwards when scrolling up

  • May 10, 2021
  • 1 reply
  • 913 views

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

 

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    May 10, 2021

    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?

    Paolo5EF8Author
    Inspiring
    May 10, 2021

    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

    kglad
    Community Expert
    Community Expert
    May 10, 2021

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

    }

    }