Adding a time delay to a for loop

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”);
}
};

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

SteveD

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

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

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.

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

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

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

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