Remember Mad Libs? We all did them as a kid—fill in blanks with nouns, verbs, adjectives, etc. and then read back a humorous story. Using Flash, you will create an interactive Mad Lib of your own. Here is a sample.
To do this we're going to make use of Flash's input text and dynamic text funcions. Input text allows the user to write text in pre-made fields (as are used in forms, etc.). Dynamic text is text that is written or altered by Flash as the program is running. In this case the user will input his/her name, then a list of nouns, verbs, etc. Flash will then output a dynamically written story using the input words.
Now we need to write several actions; these will collect the input data (name(s) of users, supplied words, etc.) and then integrate them into the story and spit everything out as dynamic text.
displayName="";
This sets up a variable ("displayName") and assigns it a null (empty) value. We will use this variable in the next frame.
stop();
button1.onRelease = function () {
gotoAndStop(3);
displayName=nameField;
}
This script does two things when the button (button1) is clicked: the playhead jumps to frame 3 and the variable "displayName" is filled with the name typed into the input text field called nameField.
greeting = "Hello "+displayName+". Is there anyone else?";
button2.onRelease = function() {
nameField = "";
gotoAndStop(4);
};
button3.onRelease = function() {
gotoAndStop(5);
};
If you recall, there is a dynamic text field on this frame called "greeting" (see step 8 above). The first line of this script causes a message to be written within it—a greeting to the user. The script then looks to see which button is pressed. If button2 is pressed, it clears the value of the variable "nameField" (sets it to null), and goes on to frame 4 where a new name can be added. if button3 is pressed we jump to frame 5 to begin the Mad Lib.
button1.onRelease = function() {
gotoAndStop(3);
displayName = displayName+", "+nameField;
};
The difference, of course, is that displayName already has a value assigned to it (the first user name entered). This script takes the new name and adds it to the first name (and throws in a comma to separate them). If the user opts to go back and add a third name, it will be added to the first two, and so on.
button4.onRelease = function() {
gotoAndStop(6);
};
storyIntro = displayName+" here is your story:";
story = "Once upon a time there lived a "+noun1+" who lived in a little room under "+place+". One day the "+noun1+" got hungry, so it "+verb1+" into "+place+" and hid in a "+noun2+". When a "+adj1+" "+noun3+" came by it "+verb2+" on the unsepecting "+noun3+" and "+verb3+" it in one bite.";
The first line writes a little personalized intro to the user. The next part of the script writes the story. Note that this is my sample story—you should create your own. Place the appropriate nouns, verbs, etc., where they belong.
4 pts |
Portfolio quality design; great Mad Lib. |
3 pts |
Good looking; above average work. |
2 pts |
It works, but it's nothing fancy. |
1 pts |
Something's not working right. |
0 pts |
Poor showing; mostly incomplete or full of errors. |