# Random Phrase Generator

**URL:** <https://forum.kirupa.com/t/random-phrase-generator/116945>\
**Category:** Uncategorized\
**Created:** [July 22, 2004, 6:34pm UTC](https://forum.kirupa.com/t/random-phrase-generator/116945 "2004-07-22T18:34:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryall](https://avatars.discourse-cdn.com/v4/letter/r/53a042/32.png) [@Ryall](https://forum.kirupa.com/u/Ryall)\
**Post date:** [July 22, 2004, 6:34pm UTC](https://forum.kirupa.com/t/random-phrase-generator/116945/1 "2004-07-22T18:34:48Z")

</div>

**(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!

[SWF](http://www.grafikdesigns.com/phraseComponent.swf)  
[FLA](http://www.grafikdesigns.com/phraseComponent.fla)

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

Peace

---

<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:** [July 22, 2004, 7:30pm UTC](https://forum.kirupa.com/t/random-phrase-generator/116945/2 "2004-07-22T19:30:12Z")

</div>

> [@Ryall](#):
>
> **(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. aplha 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!
> 
> [SWF](http://www.grafikdesigns.com/phraseComponent.swf)  
> [FLA](http://www.grafikdesigns.com/phraseComponent.fla)
> 
> I’ve also attached the .txt file that populates the array.
> 
> Peace

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(“:”);  
}  
myArray.sort(shuffle);

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

```

};  
lv.load(“var.txt”);

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.

---

<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:** [July 22, 2004, 8:50pm UTC](https://forum.kirupa.com/t/random-phrase-generator/116945/3 "2004-07-22T20:50:44Z")

</div>

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 :\

---

<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:** [July 22, 2004, 10:10pm UTC](https://forum.kirupa.com/t/random-phrase-generator/116945/4 "2004-07-22T22:10:15Z")

</div>

> [@Ryall](#):
>
> 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  
[http://www.gifsrus.com/testfile/phraseComponent.fla](http://www.gifsrus.com/testfile/phraseComponent.fla)

---

<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:** [July 22, 2004, 11:37pm UTC](https://forum.kirupa.com/t/random-phrase-generator/116945/5 "2004-07-22T23:37:46Z")

</div>

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

```auto

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

```

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:

```auto

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

```

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

---

<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:** [July 23, 2004, 4:57pm UTC](https://forum.kirupa.com/t/random-phrase-generator/116945/6 "2004-07-23T16:57:56Z")

</div>

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…
