Jump to content
Search Community

How to handle MCs created using .call from TimelineLite

rob_v_5712 test
Moderator Tag

Recommended Posts

I was wondering if anyone had a suggestion on how to handle this.

 

I have a timeline object with several tweens tied to a slider.

I can slide fwd and back and the tweens go fwd and back no problem.

 

In this instance the tweens are a list of 5 bullets.  Before using Timeline,  I had a function that I would call that would would create the bullets and tween them in on the stage.

I just added that same function to the Timeline object using .call, if I just let things play, they fire off fine.

But if I drag the slider, they don't fire / dont ff / rewind (which I can understand why they dont)

 

The idea behind using that addBullet function is I can just pass it a MC and it will add a bullet to it automatically.  I assume I need to modify my thinking in the case where I want to use the Timeline object w/ a slider.

 

Like I mentioned in the beginning, just looking for some suggestions on how to handle this situation.

(worst cast, I can just manually add the bullets to the stage first, but would rather not have to deal w/ that).

 

 

Link to comment
Share on other sites

With some more playing, this is what I was able to do to get it to work, still not sure if this is the easiest way.

 

I modified my addBullet function to create the bullets and add them to a new Timeline object, then return that object.

in my code before I create the main Timeline - I do this for each bullet :

 

var bulletTimeline1:TimelineLite = myTweens.addBullet(node_1);
var bulletTimeline2:TimelineLite = myTweens.addBullet(node_2);

all the way to 5 (1 for each bullet)

 

Then in my main Timeline object - I just add those timelines where needed :
 
.to(node_1,1,{alpha:1}, 3)
.add(bulletTimeline1,3)
.to(node_2,1,{alpha:1}, 6)
.add(bulletTimeline2,6)
etc....
 
 
This seems to work great.
The only issue is, what if I have a situation where I have 10 bullets, do I need to declare 10 new bullet timelines?  Is there a way to do that inline in the main Timeline obj so its a bit cleaner and dont have to worry about declaring a new var for each bullet?
 
 
Note : This is how I initially had it  on the timeline - and I will not ff/rewind:
.call(myTweens.addBullet,[node_1],3)
 
Link to comment
Share on other sites

Its a little hard to follow, but are you sure the addBullet() function isn't being called at all when you scrub the slider?

 

the call() should fire regardless of whether or not you are scrubbing.

 

I've attached a little demo that shows this to be the case.

Halfway through the timeline a function gets called that randomizes the color of mc

//v12import com.greensock.*;
import com.greensock.easing.*;
import fl.events.SliderEvent;




var tl = new TimelineLite({paused:true});
tl.to(mc, 2, {x:500, ease:Linear.easeNone})
.call(changeColor, [], 1);


function changeColor(){
TweenMax.set(mc, {tint:Math.random() * 0xffffff});
}

//config slider
slider.minimum = 0;
slider.maximum = tl.duration();
slider.snapInterval = 0.01
slider.liveDragging = true;
slider.addEventListener(SliderEvent.CHANGE, onChangeSlider);
function onChangeSlider(event:SliderEvent):void {
    tl.time(event.value);
}

cs5 fla attached

 

If you still have trouble, please provide a very simple file that simply illustrates the call() not firing. 

timelineSlider_call_CS5.zip

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