Hi, I have been trying to assign tween function in an array through a loop in as3.
I have 20 mc on stage, the instance names are obj1, obj2 and so on.
I want to assign a tween function to each of them, the function looks like this :
Actionscript Code:
function startTween(e:TweenEvent = null):void
{
xTween = new Tween(obj1, "x", None.easeNone, obj1.x, Math.random()*20, 0.2, true);
xTween.addEventListener(TweenEvent.MOTION_FINISH,startTween);
}
it worked, but only for obj1.
so I thought maybe I can put them in an array, var obj:Array = new Array(obj1, obj2.....);
and then I'll run a loop through it.
Actionscript Code:
for(var i:uint = 0; i < obj.length; i++)
{
function startTween(e:TweenEvent = null):void
{
xTween = new Tween(obj[i], "x", None.easeNone, obj[i].x, Math.random()*20, 0.2, true);
xTween.addEventListener(TweenEvent.MOTION_FINISH,startTween);
}
}
it doesn't work.I am not sure what went wrong.
it gave me this Error message: #1010: A term is undefined and has no properties.
Can anybody help? thanks