Jump to content
Search Community

How to stop TimelineLite on a button/MC click

heyitsjayy test
Moderator Tag

Recommended Posts

Hi there!

 

Just wondering if anyone knows, is it possible to stop and interrupt a TimelineLite sequence on a click of a button, or MovieClip?

 

The first thought was to just make a function to do something like this:

 

function stopScroll(event:MouseEvent):void{
//should be able to stop the timeline where it is currently
tl.stop();
tltwo.stop();
}

 

And here's the Timeline code below:

 

This should work-- but the thing is the TimelineLite kinda NEEDS to be in an init() function that gets activated on the start. So it doesn't seem to be working. It's looking for the Timeline variables ("Access of undefined properties") since the variables are in the init() instead of the function :

init();
function init():void{
if(number == 4){
 position = new Array (55, 181, 307, 435)
var tl:TimelineLite = new TimelineLite();
tl.insert(TweenMax.to(slider, 1, {y:position[1], delay:.4}));
tl.insert(TweenMax.to(slider, 1, {y:position[2], delay:6}));
tl.insert(TweenMax.to(slider, 1, {y:position[3], delay:8}));
tl.insert(TweenMax.to(slider, 1, {y:position[0], delay:10}));
tl.insert(TweenMax.to(slider, 1, {y:position[1], delay:12}));

var tltwo:TimelineLite = new TimelineLite();
tltwo.insert(TweenMax.to(scrollbar, 1, {y:position[1], delay:4}));
tltwo.insert(TweenMax.to(scrollbar, 1, {y:position[2], delay:6}));
tltwo.insert(TweenMax.to(scrollbar, 1, {y:position[3], delay:8}));
tltwo.insert(TweenMax.to(scrollbar, .5, {y:position[0], delay:10}));
tltwo.insert(TweenMax.to(scrollbar, 1, {y:position[1], delay:12}));
}

 

 

Does anyone have any ideas on how to solve a situation like this, where the timelines are in a different function altogether? How does the mouse Click function able to stop the Timelines in another function altogether, is basically the main question!

Link to comment
Share on other sites

try instantiating/declaring the timelinse outside the inti() functon, but building them inside the function

 

var tl:TimelineLite = new TimelineLite();
var tltwo:TimelineLite = new TimelineLite();


function init():void{

tl.insert(TweenMax.to(slider, 1, {y:position[3], delay:8}));
tl.insert(TweenMax.to(slider, 1, {y:position[0], delay:10}));
tl.insert(TweenMax.to(slider, 1, {y:position[1], delay:12}));


tltwo.insert(TweenMax.to(scrollbar, 1, {y:position[1], delay:4}));
tltwo.insert(TweenMax.to(scrollbar, 1, {y:position[2], delay:6}));
}

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...