# setInterval in a for loop - what am I doing wrong?

**URL:** <https://forum.kirupa.com/t/setinterval-in-a-for-loop-what-am-i-doing-wrong/289035>\
**Category:** flash\
**Created:** [May 25, 2009, 12:48pm UTC](https://forum.kirupa.com/t/setinterval-in-a-for-loop-what-am-i-doing-wrong/289035 "2009-05-25T12:48:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kajakki](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kajakki](https://forum.kirupa.com/u/kajakki)\
**Post date:** [May 25, 2009, 12:48pm UTC](https://forum.kirupa.com/t/setinterval-in-a-for-loop-what-am-i-doing-wrong/289035/1 "2009-05-25T12:48:33Z")

</div>

What I’m trying to achieve is that I’m planning to fetch data from an XML file in certain time sequences. For this I would need a simple function that has a growing variable. I tried to test this as a text field that would show my variable go from 0 to 2 with one second between each change - but I can’t get it to work. Could someone help me out?

```auto

for(var i=0; i<3; i++){
 timer = setInterval(countDown, 1000); 
 
 function countDown(){ 
  changing_number.text = i;
  trace(i);
  clearInterval(timer);
     }
}
 

```

Thanks in advance!
