1. Computing & Technology

Discuss in my forum

Flash Fortune-Teller/Random Sentence Generator with User Input

By , About.com Guide

Scripting the Output
Flash Fortune-Teller/Random Sentence Generator with User Input
Now double-click the movie clip to edit it, and on your timeline:
  • Copy your first keyframe to a second keyframe;
  • Clear your first keyframe to leave it blank and insert a basic stop on that frame.

    All of what we’ve done so far is just setup; now we just need to add the script that does the real work. This script goes on frame 2 of the movie clip:

     fortunevar=Math.ceil(Math.random()*3) ; 
    	if (fortunevar==1){ 
    _root.fortune.fortunetext.fortunedisplay.text="Your " + _root.noun1 + " will " + _root.adv + " " + _root.verb + " the " + _root.adj + " " + _root.noun2 + " " + _root.name + "."; 
    	} 
    	if (fortunevar==2){ 
     (etc….I think you get the idea at this point, and I’m low on space.) 

    This is, again, just like the Magic 8-ball in that it generates a random number between 0 and 1 using Math.random, rounds it to the next highest integer using Math.ceil, and then multiplies by the number of options to get a number anywhere between 1 and X (with X being how many options you have, 3 in my case). Then it uses if statements to check the value assigned to the random number generated, and when one tests as true, performs the function inside.

    What I’ve done is set up a concatenation of text plus variables, arranging the variables gathered from the input text boxes to fill in the blanks in standard sentences. For each set of variables, there are three possible outcomes for how the sentence will be arranged.

  • ©2012 About.com. All rights reserved.

    A part of The New York Times Company.