Jump to content
Search Community

Infinite loop timeline within a timeline

berilac test
Moderator Tag

Recommended Posts

Hopefully I can explain the concept simply enough :) (but if example fla required just ask)...

 

I have a nested timeline max. It has repeat:-1 and yoyo:true

This timeline begins (say) halfway through my main timeline...however, though the repeat works perfectly, the main timeline no longer progresses...

 

It's fairly simple, I guess, to see why. But I would like to know if there is a way to achieve this?

[basically, to have a main timeline running; at some point start playing new timeline (set to repeat) while still playing the main timeline]

 

Thanks

Link to comment
Share on other sites

What exactly isn't working for you?

 

The only thing I can see that would change when you have a nested infinitely repeating tween/timeline is that the parent's duration would become infinite and its "progress" value wouldn't really go anywhere because it's a measure of overall progress towards completion (and since the nested tween/timeline repeats infinitely, the parent timeline will NEVER complete). See what I mean? Sounds like it's functioning as expected, but maybe I'm misunderstanding the "problem" you meant to describe.

Link to comment
Share on other sites

I agree; the code I've used reflects what you say...

 

Is there a way then, that I can trigger a second separate timeline at this point in my main timeline?

As in, is there a way to trigger an infinitely looping movie clip at some point within a timelineLite or Max, without breaking the timeline?

 

Would it perhaps work to use a previous tweenLite/Max onComplete to call a function that creates a new timelineLite/Max instance?

*try*

 

Thank you (again) for all your help.

Link to comment
Share on other sites

well, I tried what I suggested; using onComplete.

 

The function just calls another instance of timlineMax.

However, now when the main timeline completes (with another repeat:-1 append), I have the two timelines running, but there is some lag occasionally, so I guess this is not cleanest solution.

 

Let me know if you'd like me to put together some kind of example fla...unless you already can see a way to solve this :)

Link to comment
Share on other sites

Is there a way then, that I can trigger a second separate timeline at this point in my main timeline?

As in, is there a way to trigger an infinitely looping movie clip at some point within a timelineLite or Max, without breaking the timeline?

Sorry, I'm lost - how is the timeline "breaking"? And could you post some code or (better yet) an example FLA that demonstrates what you're trying to do?

 

You can create as many TimelineLite/Max instances as you want from anywhere you want. Loop any of them. There really aren't any limitations I can think of.

Link to comment
Share on other sites

Apologies for ambiguity.

I have uploaded sample fla. By working on this I solved couple of issues.

However, I still would like to hear from you that this is an efficient way to solve such issues, and that I could repeat such a thing without much concern to memory, etc...

 

Also, you can see in the example that I have used onComplete, but when I compile I can see the rotation begin before the previous tween completes (the bounce). Is there an alternative to onComplete that achieves more what I would expect?

 

Thanks.

 

 

------ edit ---------

 

It seems I have found solutions again. The onComplete issue was to do with including parenthesese (and I should not have) when calling the function.

 

Sorry to have wasted any of your time. Though I still wouldn't mind knowing that I am coding "correctly" :)

Link to comment
Share on other sites

It seems I have found solutions again. The onComplete issue was to do with including parenthesese (and I should not have) when calling the function.

 

Sorry to have wasted any of your time. Though I still wouldn't mind knowing that I am coding "correctly" :)

Glad to hear you figured out the problem. As far as me telling you if you're coding "correctly", I'd need to see the code. :) (it doesn't look like you attached any files)

Link to comment
Share on other sites

hmm, oops. Could have sworn... oh well.

Here you are...

test_infinityLoops.zip

 

Thanks :)

 

 

btw, while I'm here, I'd like to mention something, though a little off topic.

 

In a lot of my tweens I am referring to movie clips within movieclips.

This didn't work at first, until I declared each nested movie clip as follows (ie):

var mcBio = MovieClip(this.mcHomeMenu.mcBio);

Then I am able to refer to ie/ mcBio as I normally would with TweenLite/Max.

 

Is there an alternative to this as I have a lot of nested movie clips?

Or would I perhaps have to have an array of all the movie clips and loop through using the above code?

 

Cheers

Link to comment
Share on other sites

As far as your example code goes, what you did was fine. You probably could have eliminated a few lines by utilizing the yoyo feature in the TimelineMax instance you created in toAndFro(), but that's not a big deal.

 

The only other possible down side to building it the way you did is that if you wanted to be able to stop/resume/reverse everything together, you'd need to give those instructions to both of your timelines since you have them running separately. If everything was in a master TimelineMax it'd be simpler to control. I wonder if the trouble you were running into had to do with appending an infinitely looping tween/timeline into a parent timeline and then trying to append() or appendMultiple() other tweens. Remember, "append" means putting something at the END of the timeline, so if you append something onto a timeline that has an infinite duration, you'd never really see the tween/timeline begin because its start time would be infinity. However, you can easily work around that by using insert() or insertMultiple() and defining a specific insertion time.

 

In a lot of my tweens I am referring to movie clips within movieclips.

This didn't work at first, until I declared each nested movie clip as follows (ie):

var mcBio = MovieClip(this.mcHomeMenu.mcBio);

Then I am able to refer to ie/ mcBio as I normally would with TweenLite/Max.

 

Is there an alternative to this as I have a lot of nested movie clips?

Or would I perhaps have to have an array of all the movie clips and loop through using the above code?

 

No, you don't have to do that. These are equivalent:

mcBio = MovieClip(this.mcHomeMenu.mcBio);
TweenMax.to(mcBio, 1, {x:100});

-AND-

TweenMax.to(this.mcHOmeMenu.mcBio, 1, {x:100});

 

That has nothing to do with TweenMax, just so you know - it merely has to do with valid references in AS3.

 

Does that help?

Link to comment
Share on other sites

I tried my understanding of your suggestion re insert vs append. I still had the trouble with the nested timeline halting the progress of the main timeline. Were you suggesting that the "inserted" timeline should not be nested when you mentioned using specific start time?

 

However, I'm not sure it matters, as in my main website code I seem to have solved all problems using onComplete with no parenthese in the function call, and by utilising "immediateRender:false" in varying instances.

Is this acceptable form of cleaning things up (I am still using the separate function and timeline)?

 

Regarding this:

No, you don't have to do that. These are equivalent:

 

Code: Select all

mcBio = MovieClip(this.mcHomeMenu.mcBio);

TweenMax.to(mcBio, 1, {x:100});

 

 

-AND-

 

Code: Select all

TweenMax.to(this.mcHOmeMenu.mcBio, 1, {x:100});

 

 

 

That has nothing to do with TweenMax, just so you know - it merely has to do with valid references in AS3.

 

This is what I assumed when I first began using your code but upon running into troubles searched around and ended up constructing my solution.

Is it possible that I am running into trouble as my site is running within a movie clip and not on the initial Stage (I have it separated to later create preloader)?

I get this error when I remove my code:

1120: Access of undefined property mcBio

 

Any ideas?

Many thanks again - can't fully express, regarding your level of support; it's pretty incomparable to others! :)

Link to comment
Share on other sites

I tried my understanding of your suggestion re insert vs append. I still had the trouble with the nested timeline halting the progress of the main timeline. Were you suggesting that the "inserted" timeline should not be nested when you mentioned using specific start time?

No, I wasn't suggesting that it not be nested - I was just saying that when you're nesting it, you either append() or insert(). append() always tacks it onto the end of the timeline whereas insert() allows you to position it at any spot in the timeline. If you've got an infinitely looping nested timeline in your parent timeline, then it wouldn't make sense to then append() a tween/timeline because...well...where is it going to go? At the end - but there is no end if the duration is inifinity. insert() would allow you to define the point where you want the tween to start, like insert(myTween, 5) will insert it at exactly the 5-second spot.

 

As far as it halting the progress of the main timeline, could you explain what you mean? Does everything suddenly stop? No tweens work anymore? Completely broken? Or are you just saying that its "progress" property doesn't keep getting bigger as it plays? The latter would be normal because if its duration is infinity and "progress" describes the completion ratio, it wouldn't get any bigger. If you're saying everything stops, maybe it's because you paused the parent into which you placed the tween/timeline? Tough to say without seeing an example. Also you should definitely make sure you're using the latest version of the classes just to make sure you've got all the fixes and enhancements in there.

 

This is what I assumed when I first began using your code but upon running into troubles searched around and ended up constructing my solution.

Is it possible that I am running into trouble as my site is running within a movie clip and not on the initial Stage (I have it separated to later create preloader)?

I get this error when I remove my code:

1120: Access of undefined property mcBio

Yeah, there's definitely something wrong with your code then - if your nesting looks like root > parentClip > childClip and your goal is to reference childClip, then your code will depend on scope. If the code is on the root, then you'd do parentClip.childClip. However, if your code is in parentClip, then you'd just need to reference childClip directly. It's all relative to where your code is (scope).

 

Many thanks again - can't fully express, regarding your level of support; it's pretty incomparable to others! :)

Absolutely, glad to help (or at least try). The level of support I am able to offer is directly related to the licensing model that I use for the code which keeps it totally free for 98%+ of the users out there and the power users (and kind supporters) provide a cash flow mechanism to make this all possible. So thanks to all the Club GreenSock members out there.

Link to comment
Share on other sites

Cheers!

 

Seems I found solution still using the onComplete function and append instead of insert (though I'll keep this in mind certainly - the clarity is much appreciated), by also utilising "immediateStart:false".

I shan't be needing to reverse the timeline so I didn't worry about making the changes in this instance.

 

Regarding referencing movieclip instances, as best as I can explain it...

- the site has root(Stage)>mcContent>mcHome

- I am trying to plan ahead (based on what I've studied so far) regarding later creating a preloader

- mcHome has various movie clips that I use tweenMax to animate the website intro.

- also contains an mcMenu movie clip which has several movie clips within

- it is these clips (among others in similar circumstance) that I am trying to reference.

- my main actions are currently on Frame 1 of mcHome

- actions reference, for example mcHome.mcMenu.mcBio

- this is seemingly why I am having to specifically define each mc...??? Ideas?

 

However, it should be noted that I am _very_ unsure as to how to structure a flash website.

Rather than make an example, if you're happy, I shall upload the site as it currently stands (after a little code cleanup for your benefit :)); hopefully I'll be able to tomorrow.

 

Then, if you (or anyone else) have a few minutes, I would _majorly_ appreciate any advice you may offer, re your code, or flash/as3 in general.

Also, once I am working again, if I end up using more of Flash, I will certainly be supporting you more than I am now.

Link to comment
Share on other sites

  • 2 weeks later...

I have attached a sample fla to try and express the issue I mentioned in my previous post regarding nested movie clips.

I am aware there is likely at least one level of unnecessary abstraction, but it's still a valid question.

 

How can I refer to the three discs without individually re-defining them (see line 10 in the code)? (Please read the comments as it explains in more detail)

 

stop();

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

var timeline:TimelineLite = new TimelineLite();

// --- The following for loop does _not_ work unless I explicitly define each nested mc
// --- using the following notation:
// var mcDisc1 = MovieClip(this.mcDiscs.mcDisc1);
// --- I believe this is due to the use of this[refStr].alpha (etc) with nested mc
// *** The frustrating thing is "this[refStr]" works when not referring to a nested mc!
///*
// I know the following is not necessary in this example (could use allFrom in the
// timeline.append later; but in my other file, it is necessary 
var i:int = 1;
var refStr:String;
for (i=0; i<=3; i++){
refStr = "mcDiscs.mcDisc" + i; // <- Causes error
//refStr = "mcDiscs";			// <- Causes no error!
trace(refStr);
this[refStr].alpha = 0;
}
//*/

// The following code works:
// --- I tried using this, but there is an occasion in my other project where I wish to make changes to
// --- _some_ but not all mc's within another mc (based upon a number at the end of their names)
// --- The following solution then becomes very impracticle!
/*
for(var i=0; i	this.mcDiscs.getChildAt(i).alpha = 0;
trace(this.mcDiscs.getChildAt(i).name);
}
*/

// The following code also works:
//mcDiscs.mcDisc1.alpha = 0;

timeline.append(TweenMax.from(mcBackground, 3, {alpha:0}));

timeline.appendMultiple(TweenMax.allTo([mcDiscs.mcDisc1,
							  mcDiscs.mcDisc2,
							  mcDiscs.mcDisc3],
							 3, {alpha:1}, 0.5), -1);

 

 

I should note that since beginning this post (and creating the sample fla), I have made a workable solution with ".getChildAt" - But I would still love to hear any advice you may have.

 

If you consider this to be a more generic AS3 issue, I'll take it elsewhere.

 

 

Thank you.

Link to comment
Share on other sites

Yeah, this is more of a general AS3 question, but I'd be happy to offer an answer (at least my attempt at one):

 

When you do this["myProperty"], it's basically like saying "find the property named 'myProperty' on this and return that value". So if you're trying to go a few levels deep, it's invalid to do it this way this["mc1.mc2"] because that literally is asking to find the single property named "mc1.mc2" and there is no such thing. Properties can't contain a dot/period. It would be more appropriate to do this:

 

this["mc1"]["mc2"]

 

If you really need to be able to use a String with the whole path to the property you're looking for, I suppose you could use a function like (untested):

 

function getObjectAtPath(rootObj:Object, path:String):Object {
   var a:Array = path.split(".");
   var obj:Object = rootObj;
   for (var i:int = 0; i         obj = obj[a[i]];
   }
   return obj;
}

 

Then you could do this:

getObjectAtPath(this, "mcDiscs.mcDisc1").alpha = 0;

 

Does that help?

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