Jump to content
Search Community

Can I change "repeat" value dynamically before tween cycle?

danissimo test
Moderator Tag

Recommended Posts

Hello,

 

Is there a way to change "repeat" value dynamically before each tween cycle?

I tried to use dynamicProps plug like this:

TweenMax.to (item2_2_1, 0.4, {transformAroundPoint:{point:new Point (138,300), rotation:"10"}, ease:Cubic.easeInOut, dynamicProps:{repeat:function():Number {return (Math.round (Math.random()) * 2 + 1);}}, yoyo:true})

but got an error:

ReferenceError: Error #1069: Property repeat not found on Item2_2_1 and there is no default value.

 

I wanna use dynamic repeat, delay and repeatDelay on TweenMax and TimelineMax.

Link to comment
Share on other sites

dynamicProps is useful when your target values of your tween are changing while the tween is running.

the target values are applied to properties on the object that is the target of the tween, such as the x, y, or alpha properties of a movie clip.

as your error states, your Item2_2_1 does not have a repeat property... the tween has a repeat property. just want to make that clear.

 

I don't know how it would be different if you set a random repeat value when the tween is created or while it is running so I would suggest you try

 

 

TweenLite.to(mc, 1, {x:200, repeat:(Math.random()*2) + 1, yoyo:true})

 

if that doesn't suit your needs feel free to elaborate on exactly how you want it to work. also keep in mind that the repeat value should be an integer. Your code is going to generate numbers like 1.8345949084908 and 2.3453453453, but I'm pretty sure TweenMax will convert it to an int and you won't get any errors.

Link to comment
Share on other sites

Yeah, I'm baffled by what exactly you're trying to accomplish - could you give some more details? Your code looked like you were trying to change the repeat value every single time the tween was updated which doesn't make any sense to me, so I must be missing something.

Link to comment
Share on other sites

Here's the situation: I've got a TimelineMax sequence with repeat -1 and repeatDelay 2

that contains several TweenMax's with animated rotation and 1 repeat with yoyo.

So I want to change the repeat values of that TweenMax tweens (actually to 1 or 3) at the beginning of every TimelineMax sequence cycle.

Additionally I want to change repeatDelay of my TimelineMax sequence at every cycle too.

I think this can produce some "live" effect.

Link to comment
Share on other sites

That seems like a very cumbersome way of trying to set things up, and there are some logic problems too related to the fact that you're potentially changing the duration of your parent TimelineMax after each repeat which affects the totalTime and totalDuration so you'd have to adjust the startTime to compensate and....well....I don't want to bore you, but suffice it to say that it would be much cleaner to simply create your TimelineMax and use an onComplete to call a function that creates a new TimelineMax according to your specifications each time. That'll give you exactly the same effect (if I understand it correctly) and avoid overly complex logic issues with switching things around on-the-fly like you were trying to do.

 

function buildRandomAnimation():void {
   var tl:TimelineLite = new TimelineLite({delay:Math.random(), onComplete:buildRandomAnimation});
   tl.append( TweenMax.to(mc, 1, {x:200, repeat:(Math.random()*2) + 1, yoyo:true}) );
   ...
}
buildRandomAnimation();

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