# Using A Tween in a For Loop

**URL:** https://forum.kirupa.com/t/using-a-tween-in-a-for-loop/290182
**Category:** flash
**Created:** [June 10, 2009, 9:34pm UTC](https://forum.kirupa.com/t/using-a-tween-in-a-for-loop/290182 "2009-06-10T21:34:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![thewriteleague](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@thewriteleague](https://forum.kirupa.com/u/thewriteleague)
#### Post date: [June 10, 2009, 9:34pm UTC](https://forum.kirupa.com/t/using-a-tween-in-a-for-loop/290182/1 "2009-06-10T21:34:09Z")

</div>

Trying to use a tween in a loop and apply it to each dynamically created movieclip, not as a block after the fact. here is the sample code:

import fl.transitions._;  
import fl.transitions.easing._;  
import flash.display.\*;

stage.frameRate = 30;

for (var i:int = 1; i \< 5; i++)  
{  
var rectMC:String = “rect”.concat(i);  
this[rectMC] = new MovieClip();  
this[rectMC].graphics.beginFill(Math.random() \* 0xFFFFFF);  
this[rectMC].graphics.drawRect(100\*i,100,100,100);  
this[rectMC].graphics.endFill();  
addChild(this[rectMC]);  
var fadeIn:Tween = new Tween(this[rectMC], “alpha”, None.easeNone, 0, 1, 60, false);  
}

The actionscript code works fine, except for the tween, which is applied on all the sample rectangles at once. I want to fade in the rectangles (or any other dynamically created movieclips in loops) one at a time. Any ideas would be a great help. Thanks.
