How to create a random effect with "setInterval"

[font=Times New Roman][size=3]By way of practice I wanted to create a “Typewriter” effect output to display a “Welcome” message followed by a users name (please click [/size][/font]HERE[font=Times New Roman][size=3]), which would have been inputted in the first frame of a movie.[/size][/font]

[font=Times New Roman]Using the below code everything works great, but……[/font]

[font=Times New Roman]How can I get the loop typing out the users name to do so in a more random “timed” fashion, like it would be on a real typewriter, where there would be a delay before each “clack” as the person using the machine hunted for the correct keys.[/font]

[font=Times New Roman]The “Welcome” part has got the right feel, as obviously this is not created dynamically. I have tried a “setInterval” function but obviously this just sets the timing once for the whole loop, as the loop will have executed or started to execute before the set interval would have expired.[/font]

[font=Times New Roman]Any help please.[/font]

[color=darkorange][font=Times New Roman][color=blue]FRAME 2[/color][/font] [/color]

[font=Times New Roman][color=darkorange]tip=new Array();[/color][/font]

[font=Times New Roman][color=darkorange]for(n;n<flip.length;n++){[/color][/font]

[font=Times New Roman][color=darkorange]sank+=flip.charAt(n) + “,”}[/color][/font]

[font=Times New Roman][color=darkorange]sank=sank.slice(0,-1);[/color][/font]

[font=Times New Roman][color=darkorange]sank=sank.split(",");[/color][/font]

[font=Times New Roman][color=darkorange]my_fmt=new TextFormat();[/color][/font]

[font=Times New Roman][color=darkorange]my_fmt.color=0x666666;[/color][/font]

[font=Times New Roman][color=darkorange]my_fmt.size=40;[/color][/font]

[font=Times New Roman][color=darkorange]my_fmt.font="_typewriter";[/color][/font]

[font=Times New Roman][color=darkorange]count=0[/color][/font]

[font=Times New Roman][color=darkorange]for(r=0;r<sank.length;r++){[/color][/font]

[font=Times New Roman][color=darkorange]count++[/color][/font]

[font=Times New Roman][color=darkorange]root.createTextField("f "+count,count,50*count,100,50,50);[/color][/font]

[font=Times New Roman][color=darkorange]root["f " +count].setNewTextFormat(my_fmt);[/color][/font]

[font=Times New Roman][color=darkorange]root["f " +count]._visible=true;[/color][/font]

[color=darkorange][font=Times New Roman]}[/font] [/color]

[font=Times New Roman][color=blue]OTHER FRAME[/color][/font]

[font=Times New Roman][color=darkorange]stop();[/color][/font]

[font=Times New Roman][color=darkorange]car=1;[/color][/font]

[font=Times New Roman][color=darkorange]cart=0;[/color][/font]

[font=Times New Roman][color=darkorange]function show(){root["f " +car].text=sank[cart];[/color][/font]

[font=Times New Roman][color=darkorange]my_sound=new Sound();[/color][/font]

[font=Times New Roman][color=darkorange]my_sound.attachSound(“beak”);[/color][/font]

[font=Times New Roman][color=darkorange]my_sound.start()[/color][/font]

[font=Times New Roman][color=darkorange]car++;[/color][/font]

[font=Times New Roman][color=darkorange]cart++[/color][/font]

[font=Times New Roman][color=darkorange]if (cart>=sank.length){clearInterval(int)};[/color][/font]

[font=Times New Roman][color=darkorange]};[/color][/font]

[font=Times New Roman][color=darkorange]int=setInterval(show,Math.floor(Math.random()*3000)+1);[/color][/font]

check my typing component (see the link in my sig)

simply set up a setInterval which clears itself and then calls the setInterval function again with a random number (its in my component, take it apart to have a look…

Prophet.

Thanks Pof,

I would love to take a look at your component especially the fla, but when I clicked on the link at the end of referenced posting & downloaded the zip file, all that was in it was an acrobat reader file which failed to open?

I should be able to manage with the method you have recommended but if that fla is knocking about I would be keen to take a look.

Thank you for your suggestion of clearing the interval - I still have the palm print on my forehead from the slap of anguish I gave myself on reading your post & not thinking of that myself!

hmmm… u sure?
its packaged as a .mxp - u need to install it via the macromedia extension manager… cant repost the file coz ive already uploaded it once :S try it again an lemme know…
Prophet.

No problem Prof - I didn’t realise I had to use the extension manager, I’ll try again.

Ps Sorry for the typo in my last posting - I think the term “Pof” has only got negative connotations here in the UK
. :wink:

yeah u did baffle me a bit ther wit the pof thing… lol meh ive been called worse an it still dont bovr me! :stuck_out_tongue: lol

Prophet.