# Adding a time delay to a for loop

**URL:** <https://forum.kirupa.com/t/adding-a-time-delay-to-a-for-loop/21432>\
**Category:** flash\
**Created:** [May 21, 2003, 3:43pm UTC](https://forum.kirupa.com/t/adding-a-time-delay-to-a-for-loop/21432 "2003-05-21T15:43:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mattski](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@Mattski](https://forum.kirupa.com/u/Mattski)\
**Post date:** [May 21, 2003, 3:43pm UTC](https://forum.kirupa.com/t/adding-a-time-delay-to-a-for-loop/21432/1 "2003-05-21T15:43:48Z")

</div>

Could someone help me to put a time delay in the for loop. Here is my code as it is now. i have tried many combinations with setInterval with no luck.

Thanks.

The code:

loadVarsText = new loadVars();  
loadVarsText.load(“test.txt”);

loadVarsText.onLoad = function(success) {  
if (success) {  
trace(“done loading”);  
scroller.text ="";  
var pieces = this.var1.split("\r")  
for(var t=0;t\<=pieces.length;t++){  
setInterval(scroller.text = scroller.text + pieces[t], 10000);  
trace(t);  
}  
} else {  
trace(“not loaded”);  
}  
};

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 21, 2003, 9:12pm UTC](https://forum.kirupa.com/t/adding-a-time-delay-to-a-for-loop/21432/2 "2003-05-21T21:12:36Z")

</div>

Hi,  
Can you explain what you are trying to achieve - why do you want the delay ?

SteveD

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2003, 12:05am UTC](https://forum.kirupa.com/t/adding-a-time-delay-to-a-for-loop/21432/3 "2003-05-22T00:05:18Z")

</div>

I would like to output 1 array String variable in the text box every 30 seconds or so.

I have read the textfile into an array variable, and want to pause the output every seconds.

Basically, it is a Sports Commentary textbox, and so output every line at once isn’t what I want to happen

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2003, 6:39am UTC](https://forum.kirupa.com/t/adding-a-time-delay-to-a-for-loop/21432/4 "2003-05-22T06:39:41Z")

</div>

Hi Matski,  
OK, I think I understand what you want, like a sort of news ticker where the info appears one line at a time. Unfortunately, I am not sure how to achieve this. However, I have been delving ever deeper into the world of arrays ( with the help of Colin Moock) and would be happy to take a look, can you post your fla.  
You could also try doing search here, at Flashkit and Actionscript .org, I know I have seen something very similar somewhere…

Cheers

SteveD

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2003, 7:17am UTC](https://forum.kirupa.com/t/adding-a-time-delay-to-a-for-loop/21432/5 "2003-05-22T07:17:07Z")

</div>

Thanks mate. Basically i’m very new to Flash, but have some Java experience so that’s helping. I’ve just used samples from the web to collate and try to get the code working before i attempt to incorporate it into my project.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2003, 1:36pm UTC](https://forum.kirupa.com/t/adding-a-time-delay-to-a-for-loop/21432/6 "2003-05-22T13:36:02Z")

</div>

Hi Mattski,  
My original post suggesting a search of a various forums was the right way to go.  
Without making comments about your code ( your direction was right), I could see once i opened the fla that it wouldn’t work. I went on a search and found a variety of stuff, unfortunately most of it in F4 that I couldn’t ( haven’t the time) to update. THEN… I stumbled accross an MX component called ticker ( oh yes it is) and it does everything that you want it to do.  
This one has been adapted by someone over at actionscript .org to accept urls - so, first of, open the fla, make sure the properties panel is open and click on the scroller and then open parameters ( in the properties panel), you will see at a glance how to alter the various parameters, add headlines, etc etc. If you want to link your headliners to a specific news story, just type the address where it says URL. Although you can put all your headliners into the parameters panel, you can also load them in using LoadVars from a txt file.  
Let me know if it is what you want

Cheers

SteveD

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 23, 2003, 4:08am UTC](https://forum.kirupa.com/t/adding-a-time-delay-to-a-for-loop/21432/7 "2003-05-23T04:08:56Z")

</div>

that’s impressive, but unfortunately its not exactly what i need 🙂

i’ve read each line into the array as you would have noticed. but i want to output one array element in a textfield at a time.

Eg. the text field…

## Commentary:

Start of Quarter

Then 30 seconds later…

## Commentary:

Smith scores a goal.

Start of quarter.

So the next array element goes up the top, and they aren’t all in the text-field at the start.

Cheers  
Matt

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 23, 2003, 5:07am UTC](https://forum.kirupa.com/t/adding-a-time-delay-to-a-for-loop/21432/8 "2003-05-23T05:07:05Z")

</div>

Hi Mattski,  
Try reducing the size of the text field so that it only display one line of text - have you looked at the tute on this site, got to **Tutorials** and look for news flasher

SteveD
