Random Phrase Generator

(Flash MX)
I’ve basically finished this project, but there are some feature I’d like to add which are giving me trouble. Heres the jist of the fla

It takes data from a txt file and uses split() to put that data into an array (a list of phrases). Then it randomly chooses one of these phrases and displayes it in a text field, then it repeats this every 5 seconds.

What I am trying to add are these two things:

  1. do not repeat array value until all have been used once
  2. alpha fade in and out of each phrase, the AS of which is basic, but I am not sure where to put the code and set it up in this case.

Im just confused on where to place and exactly how the write the code for these additional elements. Help would be appreciated!


I’ve also attached the .txt file that populates the array.


I can`t open your fla but for the first part, rather than taking elements out of the array, it may be easier just to shuffle the array and then loop through.

something like this should work

shuffle = function () {
return Math.round(Math.random());
lv = new LoadVars();
myArray = [];
lv.onLoad = function() {
for (i=0; i<5; i++) {
myArray* = lv[“var”+i].split(":");

for (var n = 0; n != myArray.length; n++) {
	trace("myArray["+n+"] - "+myArray[n]);


for the second part, there are tons of fadein/fadeout tutorials around but when using dynamic text, you have to remember to embed font outlines.

I’ve attached the fla, you should be able to see it now.

I like the idea of shuffling the array and then going through it once, I;ll look into that.

The alpha fade effect is easy thats not the problem, where to place it to work properly is more like it. How do I set it up so that when the time is up for one value it fades it out then fades in the other :\

Just done it with a rectangle which fades in and out over the top -
hope it helps

I’ve done this one, and this is how I did it:

nextnum = Math.ceil(Math.random()*(slogans.length-1));
newslogan = slogans[nextnum];

it simply picks a random number between 0 and the array length, pulls the data into ‘newslogan’ and removes that data from the array.

I guess, to have it repeat, just have a:

if (slogans.length<1) {
 //repopulate array

although the shuffle idea is good too, and both will give you practically the same output anyway :slight_smile:

You’d need an if statement there, dal platinum, or else you would spam some undefined’s once you delete everything. I’d say if the length==1, re-load (repopulate, refill) the array and restart putting random quotes…