Search code examples
animationactionscriptactionscript-2tween

AS2: Dynamic tween identifier


How do i go about setting the tween identifier dynamically. I have tried eval but it says I need a variable on the left of the assignment operator. here's what I tried:

eval ("TweenAX" + circle.current.arrowHead.count) = new Tween(circle.current.arrowHead, "_x", mx.transitions.easing.Strong.easeOut, circle.current._x, Stage.width/2, 2, true);
eval ("TweenAY" + circle.current.arrowHead.count) = new Tween(circle.current.arrowHead, "_y", mx.transitions.easing.Strong.easeOut, circle.current._y, Stage.height/2, 2, true);

Cheers


Solution

  • I'm not 100% sure I understand what you are trying to achieve, but I think you're looking for the bracket syntax:

    this["TweenAX" + circle.current.arrowHead.count] = new Tween(circle.current.arrowHead, "_x", mx.transitions.easing.Strong.easeOut, circle.current._x, Stage.width/2, 2, true);
    this["TweenAY" + circle.current.arrowHead.count] = new Tween(circle.current.arrowHead, "_y", mx.transitions.easing.Strong.easeOut, circle.current._y, Stage.height/2, 2, true);
    

    This will create two properties on this named TweenAXN and TweenAYN where N is the value of circle.current.arrowHead.count