Jump to content
Search Community

problem with tweening a frames-based timeline backwards

elsa test
Moderator Tag

Recommended Posts

Hi,

 

thank you team greensock for the terrific work you're doing! I'm a big fan of your engine and your support!

 

In my project I'd like to go forth and back on the timeline of a movieclip (which has a bitmap on each frame) while scrolling with my mouse wheel. For that I am creating a frames-based tweenMax and adding it to an also frames-based timelineMax. Then I am using the "tweenTo" method to go forwards or backwards on the timelineMax according to the values I create while scrolling.

 

Tweening forwards seems to work, but it wouldn't tween back when the value decreases again. 

 

I attached a demo file with a simple rectangle moving to the side, instead of the bitmaps, on each frame. 

 

As you might have noticed I am quite new to actionscript, so I am really happy if anyone would like to give me a hint. 

 

Greetings from Germany

elsa

DEMO.zip

Link to comment
Share on other sites

the only thing that stood out as being problematic was that you were using your createTween function as an ENTER_FRAME listener which means it was creating a new tween in your timeline 30 times per second (based on the frame rate).

 

Please try this modified code

 

import com.greensock.*;
import com.greensock.easing.*;
import flash.events.MouseEvent;
import flash.events.Event;


var myDeltaVar:int;
var frameAmount:int=new int(1);
var myFrameAmount:int=1;


var tl:TimelineMax=new TimelineMax({useFrames:true,paused:true});


//don't do this
//stage.addEventListener(Event.ENTER_FRAME,createTween);
stage.addEventListener(MouseEvent.MOUSE_WHEEL,mouseDelta);


function mouseDelta(e:MouseEvent):void{
myDeltaVar=e.delta;
scrollMc();
}


function scrollMc():void{
if(myDeltaVar>0 && frameAmount>=2){
frameAmount-=myFrameAmount;
}
if(myDeltaVar<0 && frameAmount<=mc.totalFrames-1){
frameAmount+=myFrameAmount;
}
trace(frameAmount);
tl.tweenTo(frameAmount);
}


function createTween():void{
var mcTween:TweenMax = new TweenMax(mc, mc.totalFrames, {frameLabel:"end", ease:Linear.easeNone, useFrames:true/*, paused:true*/});
tl.add(mcTween,0);
}


//only call createTween once
createTween()

I didn't investigate exactly what you are doing in scrollMc but it seems that mousewheel movement allowed the timeline to go back and forth.

 

*note on Mac I had to test in  a browser as it seems that mousewheel events are ignored when you test in Flash Pro

Link to comment
Share on other sites

It's working fine now! You two are geniuses!

Thank's so much for helping out with my beginners mistake!

 

 

*on pc I have to click on the swf before it reacts to my mousewheel everytime I test!?

Link to comment
Share on other sites

Yes, the swf needs focus before responding to mouse wheel events.

There are some javascript solutions that work in some browsers, but I haven't researched it in awhile. Start with a google search of "Flash mouse wheel focus".

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...