0
votes

I have added:

sub1_btn

Within sub1_btn there is a movieclip called "arrow".

Using this code I am able to access it and tween it:

TweenMax.to(sub2_btn.arrow, 1, {rotation: -0});

However, using this code within a FOR statement (as there are 2), I am not

for (var i:int = 1; i<3; i++){
                TweenMax.to(["sub"+i+"_btn"].arrow, 1, {rotation: -0});
            }

What is wrong with the above code? The error is:

Error: Cannot tween a null object. at com.greensock::TweenLite() at com.greensock::TweenMax() at com.greensock::TweenMax$/to() at src::main/pullSub()

1

1 Answers

0
votes

Try this instead:

for (var i:int = 1; i<3; i++){
    TweenMax.to(this["sub"+i+"_btn"].arrow, 1, {rotation: -0});
}

The problem is that ["sub"+i+"_btn"] creates a new array, and that array doesn't contain an object arrow. But when you use this["sub"+i+"_btn"] you access the movie clip sub[i]_btn as you want.