A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: assigning tween function in an array through a loop AS3

Threaded View

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    4

    assigning tween function to an array through a loop AS3

    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
    Last edited by mudman; 03-17-2010 at 09:27 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center