0

I have the following code which works perfectly:

    updaterVariable = 0;
    Tweener.addTween(this, {time:2, transition:"linear", updaterVariable:1000, onUpdate:tweenerUpdate});

I will get the value of updaterVariable tweened from 0 to 1000 in 2 seconds. My question is whether there is a similar way to tween a variable in an array, for example:

    updaterVariable[10] = 0;
    Tweener.addTween(this, {time:2, transition:"linear", updaterVariable[10]:1000, onUpdate:tweenerUpdate});

I tried the above code, and its not working. Can anyone help?

1 Answer 1

1

You can pass your array to the tweener and use index as a field to be changed:

updaterVariable[10] = 0;
Tweener.addTween(updaterVariable, {time:2, transition:"linear", '10':1000, onUpdate:tweenerUpdate});

Not sure which tweener you are using, however it works with TweenMax:

private var arr:Array;
public function Main() {
    arr = [];
    arr.push(0);
    arr.push(0);
    arr.push(t);
    TweenMax.to(arr, 1000, { '2' : 1000 } );
    addEventListener(Event.ENTER_FRAME, onframe);
}
private function onframe(e:Event):void {
    trace(arr[2]);//outputs expected numbers
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for the answer. But it wont work if I place a variable like "i" in place of "10" right? Is there any way to work it out?
Because I may need to change the values around and cant always pass the index as string.
@AbhilashK, it depends on the task. You may use a getter function like public function get i():int { return arr[10]; } for example. The question is - why do you need to use an array for tweening if you know you need to tween a variable at a certain index?
@AbhilashK because primitive types are passed by value and a = 2; arr.push(a); a++; trace(a, arr[0]); will output 3, 2, not 3, 3 as it would happen if arr[0] stored a reference to a

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.