Jump to content
Search Community

Stopping a nested timeline

berilac test
Moderator Tag

Recommended Posts

Having a problem. I've tried to explain it within the following semi-pseudo code:

 

stop();

import com.greensock.*;
import com.greensock.easing.*;

var timeline:TimelineLite = new TimelineLite();

timeline.append(tweenlite(foo, $, {onComplete:newTl}));

function newTl():void{
var tlTwo:TimelineLite = new TimelineLite();

tlTwo.append(foo);
}

function Click(){
timeline.stop();	<-- THIS WORKS FINE
tlTwo.stop();		<-- THIS DOES NOT WORK
					--- CAUSES ERROR BECAUSE THE tlTwo IS DECLARED WITHIN
					--- A FUNCTION.
					---- IF I DECLARE IT AT TOP, tlTwo WILL BEGIN CALCULATING
					---- ON ENTER FRAME, AND NOT WHEN FUNCTION IS CALLED!
					---- IT WORKS BUT THIS IS UNDESIRABLE
}

 

This is the error (pretty self-explanatory):

"1120: Access of undefined property tlTwo"

- Source: tlTwo.stop();

 

 

Is this an AS3 issue or can I (for instance) prevent the timeline from immediately calculating with some of your code?

 

Thank you

Link to comment
Share on other sites

The problem has to do with variable scope. Whenever you define a variable inside a function using "var ", that variable is ONLY available inside that function. It ceases to exist once that function finishes running. You can, however, define the variable as a class or instance property like you did with "timeline" in your example. Basically, define it outside your function. You can populate it inside your function though.

Link to comment
Share on other sites

I believe I tried as you suggested, still using "var"...but declaring it at the same time as the main timeline.

I thought I explained myself better - When I did this, the tlTwo begins "calculating" immediately onEnterFrame, so when my appends are sent from the function, they don't start smoothly; they appear to start mid-tween.

 

I have currently solved this by utilising "tlTwo.currentProgress = 0" as the first line in my append function.

 

Is that the cleanest solution?

 

-- As an aside. Elsewhere in my code I have a TweenMax.allTo (not within a timeline) that calls an onComplete function.

-- I can see in some trace outputs that the function gets called for each mc I have in the allTo array.

--- Is there a way to have the function only called once? (Otherwise the only solution I see is to use a timeline, use allTo for all except one mc, and place a second TweenMax.to to do the last mc and the onComplete call... - This seems too complicated for your code though ;))

 

Thank you again

Link to comment
Share on other sites

if you have your tlTwo defined outside any functions and paused, it might work. I haven't studied your code thoroughly.

var tlTwo:TimelineLite = new TimelineLite({paused:true});

 

as for why is seems that your timeline is skipping to mid tween, read GreenSock's first response in this thread as I believe it pertains to your situation:

viewtopic.php?f=1&t=3508&p=13627&hilit=rootTimeline#p13627

 

his second resonse here also seems express the same theory:

viewtopic.php?f=1&t=2276&p=8541&hilit=rootTimeline#p8541

 

-----

 

as for your allTo issue. use onCompleteAll. onCompleteAll will fire after all the allTo tweens have finished.... very handy.

http://www.greensock.com/as/docs/tween/ ... tml#allTo()

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