Jump to content
Search Community

TweenMax new value on yoyo / repeat

phillip_vale test
Moderator Tag

Recommended Posts

Hi all,
I am relatively new to Greensock and thought I was going well but have hit a small challenge.
I am trying animate the effect of a volume equalizer going up and down.
To keep it looking as natural as possible i wanted to vary the heights that the levels rise to.
However, when I run the below code it picks the last number that the function generates and then doesn't 'refresh' a new value when the loop repeats. Is there a way to call randomRange everytime the tween repeats?
function randomRange(min:Number, max:Number):Number {
    var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
    return randomNum;
for (var i = 0; i < 1; i++) {
    var n:Number = randomRange(-27, -72) // Audio levels between these 2 numbers.

TweenMax.to(Object(this).main.window1.shade, .2, {_y:n, yoyo:true, repeat:-1, delay:.2});
TweenMax.to(Object(this).main.window2.shade, .2, {_y:n, yoyo:true, repeat:-1, delay:.3});
TweenMax.to(Object(this).main.window3.shade, .2, {_y:n, yoyo:true, repeat:-1, delay:.4});

Thanks for any help that is given,

Phil :)


Link to comment
Share on other sites

I think the best thing to do is just create new tweens each time the animation repeats


Here is an HTML5 demo but the AS3 syntax will be nearly identical


function animate(obj) {
  TweenMax.to(obj, 0.5, {x: Math.random() * 500, repeat:1, yoyo:true, onComplete:animate, onCompleteParams:[obj]})

animate("#redBox"); //in AS3 use DisplayObject



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