Random text message

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

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:

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

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

NM

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

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

Use loadVars, it will be less painful.

pom :asian:

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

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:

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

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)

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

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

Did anybody say tutorial? Inigo?

pom :stuck_out_tongue:

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

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.