# Random text message

**URL:** <https://forum.kirupa.com/t/random-text-message/940>\
**Category:** Uncategorized\
**Created:** [August 3, 2002, 4:06pm UTC](https://forum.kirupa.com/t/random-text-message/940 "2002-08-03T16:06:07Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![captnfcko](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@captnfcko](https://forum.kirupa.com/u/captnfcko)\
**Post date:** [August 3, 2002, 4:06pm UTC](https://forum.kirupa.com/t/random-text-message/940/1 "2002-08-03T16:06:07Z")

</div>

need help setting up a random message to be displayed with in the flash document. im trying to set up some sort of e-card that will display one of 100 or so random messages with in the flash document not a java pop up or anything like that. not sure how to go about it would be easier if i could somehow link it to an external document with 100s of messages but ill take any suggestions. thanks

---

<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:** [August 3, 2002, 4:26pm UTC](https://forum.kirupa.com/t/random-text-message/940/2 "2002-08-03T16:26:12Z")

</div>

If your messages aren’t too long, you can put them in an array and then output a random element of that array.

pom :asian:

---

<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:** [August 3, 2002, 5:44pm UTC](https://forum.kirupa.com/t/random-text-message/940/3 "2002-08-03T17:44:30Z")

</div>

…or load from a text file using LoadVars();

---

<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:** [August 4, 2002, 9:05pm UTC](https://forum.kirupa.com/t/random-text-message/940/4 "2002-08-04T21:05:56Z")

</div>

an example would be great…i am new to action scripting and am in the process of learning. thanks to those who replied.  
captnfcko

---

<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:** [August 5, 2002, 4:43am UTC](https://forum.kirupa.com/t/random-text-message/940/5 "2002-08-05T04:43:21Z")

</div>

NM

---

<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:** [August 5, 2002, 4:58am UTC](https://forum.kirupa.com/t/random-text-message/940/6 "2002-08-05T04:58:32Z")

</div>

This code should work try this.

store\_sentences = new Array();  
store\_sentences[0] = “Hello and Welcome”;  
store\_sentences[1] = “Hope you have a good day!”;  
store\_sentences[2]= “What is up with this weather?”;  
store\_sentences[3] = “Its sunny out!”;  
store\_length = store\_sentences.length  
process.text = store\_sentences[Math.floor(Math.random() \* 4)];

I attached a .fla to help just in case.

Hope this helps

Kyle  
🙂

---

<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:** [August 5, 2002, 8:04am UTC](https://forum.kirupa.com/t/random-text-message/940/7 "2002-08-05T08:04:02Z")

</div>

im gonna try that its gonna suck cause it totaled up to 300+ individual messages so i got a lot of typing to do…ill put up a link when im done…(its only gonna have a few of the messages)  
captnfcko  
thanks iceman and others

---

<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:** [August 5, 2002, 8:47am UTC](https://forum.kirupa.com/t/random-text-message/940/8 "2002-08-05T08:47:04Z")

</div>

Use loadVars, it will be less painful.

pom :asian:

---

<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:** [August 5, 2002, 11:23pm UTC](https://forum.kirupa.com/t/random-text-message/940/9 "2002-08-05T23:23:34Z")

</div>

ilyaslam\*\*\*e how would i incorporate the loadvars into the code to work…

---

<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:** [August 5, 2002, 11:27pm UTC](https://forum.kirupa.com/t/random-text-message/940/10 "2002-08-05T23:27:19Z")

</div>

Hey captnfcko,  
I just noticed that as well. I just modified some settings and made sure that won’t happen. Examples:

grass  
mass  
ilyaslamasse

Cheers!  
Kirupa :bandit:

---

<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:** [August 6, 2002, 12:01am UTC](https://forum.kirupa.com/t/random-text-message/940/11 "2002-08-06T00:01:12Z")

</div>

For an intro I did, I wanted a random quote at the end. I used an array and a random number algorithm to output the quote, I think thats the best way to do it, as its very easy to add or delete the text.

to generate a random number I would use this :

Mynumber = Math.random() \* 100 +1;  
thenumber=Math.round(Mynumber);

this will generate a random number between 1 and 100.

Create an array as someone showed above with the text you want, then put your random number into the field to generate the output.

texttoprint=store\_sentances(thenumber);

link that to a dynamic text field with the variable “texttoprint”

and you will get your random text 🙂

[www.westwoodexposed.com](http://www.westwoodexposed.com) is the intro I did (PS. at time of print site is down may be up by the time you read this)

---

<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:** [August 6, 2002, 4:01am UTC](https://forum.kirupa.com/t/random-text-message/940/12 "2002-08-06T04:01:06Z")

</div>

this place is great thanks guys would i be correct in saying that if i pluged in the loadvars inplace of  
texttoprint=loadvars (somewhere inhere)store\_sentances(thenumber)  
it would load a text file?  
coding newbie sorry  
captnfcko

---

<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:** [August 6, 2002, 2:59pm UTC](https://forum.kirupa.com/t/random-text-message/940/13 "2002-08-06T14:59:27Z")

</div>

how should i format a txt file to loadVars from it. i need the “vars=” at the top and then what do i need to denote the end of one var and the beginning of the next. how would the code that i insert into the flash movie look …

store\_sentences = new Array();  
loadVars = “vars.txt”;  
store\_length = store\_sentences.length  
process.text = store\_sentences[Math.floor(Math.random() \* 4)];

something like that ?

why does it need to store the length of the sentences?

is there a tutorial on this that is pretty comprehensive? i really have a lot of questions about it and am quite interested but i don’t want to waste your time if i can go read what someone has already type. i really love being able to load things from external files … it cuts down so much on load time and update headaches.

thx

---

<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:** [August 6, 2002, 8:48pm UTC](https://forum.kirupa.com/t/random-text-message/940/14 "2002-08-06T20:48:39Z")

</div>

Did anybody say tutorial? Inigo?

pom 😛

Oh, and now that I think of it, there’s an example of loadVars in Kir’s tute about the loaded text and scrollbar.

---

<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:** [August 6, 2002, 8:54pm UTC](https://forum.kirupa.com/t/random-text-message/940/15 "2002-08-06T20:54:12Z")

</div>

omgosh no … not loaded text and scrollbars … !!

i’ve done like 5 tutes for that and i can never get the \*\*\*\* thing to work right … especially when i try to use that “easier to use” component set in mx … bah! … stupid scroll bars.
