Free Flash Tutorials

Home • Members Tutorials Forum iSnapChat Contact Us 

 


Flash Tutorials

   

Flash - Interactive text box

108 Intermediate
Flash Compatibility: MX

Written by: Paul Kinsella Stickman Murder Mystery Games
Editor: Phil Schulz
Sub Editor: Wendy Saunders

Length: 800 words

Assumed Knowledge: Buttons, Basic ActionScript, Creating Input boxes, naming frames, Instance names. If you have difficulties with any of these do the password tutorial. It is a click by click tutorial and can achieve a similar result.

 

The aim of the tutorial is to show you how to make a text box that: Depending on what you type, you get a different outcome.

 

Example: Download the Flash file   Int 108a

 

Example of an interactive text box.

How to make an "interactive text box":

  1. Make an input text box
  2. Give it a Instance name: textbox
  3. Draw/make/add a button.
  4. Place the button on stage and add the following code:

       on (press) {
          if (textbox.text.indexOf("car") != -1) {
              _root.gotoAndStop("saw");
          } else {
             _root.gotoAndStop("what");
          }
       }

"car" is the interactive keyword.

"saw" is the name of the frame of whatever scene the reader is to be sent to if they type in the keyword "car".

"what" is the name of the frame of whatever scene the reader is to be sent to if they DON'T type in the keyword "car".

(you will need to give the frames names to do this. The frames can be on same or different scenes)

One use for this code can be for Role Playing Games (RPG's). Let's say you have a detective RPG and you want the player to interact with a hot-dog vender. In the example above - if the player types a sentence with the word "car" in it, the player will be taken to a frame named "saw". If the player types a sentence without the word "car" in it, then the player will be taken to a frame named "what".

If player types "did you see a car go by this way?" --- hot-dog vender might reply "yes, I saw a car."

If player types "did you see a dog go by?" --- hot-dog vender might reply "what? I don't understand."

Here is a more complicated code that uses "||", "&&" and "&!"

|| means or
&& means and
&! means but not

Note: In the ActionScript above to type the line: | use: Shift + Back Slash \

Also textbox.text = textbox.text.toLowercase(); makes it non-case sensitive.

on (press, keyPress "<Enter>") {
   textbox.text = textbox.text.toLowercase();
   if (textbox.text.indexOf("car") != -1 || textbox.text.indexOf("auto") != -1 || textbox.text.indexOf("red") != -1) {
      _root.gotoAndStop("saw");
   } else if (textbox.text.indexOf("tires") != -1 || textbox.text.indexOf("flat") != -1 || textbox.text.indexOf("tread") != -1) {
      _root.gotoAndStop("tireshop");
   } else if (textbox.text.indexOf("hot") != -1 && textbox.text.indexOf("dog") != -1) {
      _root.gotoAndStop("hotdog");
   } else if (textbox.text.indexOf("hot") != -1) {
      _root.gotoAndStop("hotout");
   } else if (textbox.text.indexOf("dog") != -1) {
      _root.gotoAndStop("doghouse");
   } else if (textbox.text.indexOf("house") != -1 && textbox.text.indexOf("white") != -1) {
      _root.gotoAndStop("whitehouse");
   } else if (textbox.text.indexOf("house") != -1 &! textbox.text.indexOf("white") != -1) {
      _root.gotoAndStop("hishouse");
   } else {
      _root.gotoAndStop("what");
}
}

"Have you seen an auto?" (used "auto" or "car" or "red")  "Yes, I saw a red car go by.. it had 4 flat tires."
"Did you see a red car go by?" (used "auto" or "car" or "red") "Yes, I saw a red car go by.. it had 4 flat tires."
"See any broken tires today?" (used "tires" or "flat" or "tread") "I saw a car with 4 flats go by.. it was red."
"May I have a hot dog?" (used both "hot" and "dog") "I'm out of hot dogs."
"Boy! it is hot out?" (used "red") "Yes, It is very hot today."
"Did you see a dog around here?" (used "dog") "Yes, I saw a dog run into that taxi."
"Where is the white house?" (used both "white" and "house") "The white house is up the street."
"Whose house is that?" (used "house" but not "white") "My house is green."
"Is that a dog house?" (used "dog") "The dog ran from the dog house into the taxi."
"Is your door painted white?" (not applicable) "What? I don't understand."

 

Please indicate what you thought of this tutorial 
10 is the best: 
10 9 8 7 6 5 4 3 2 1


77848 visitors to this page since Jan 04

Phil Schulz's Facebook Profile
Webwasp is Phil Schulz's baby. You are welcome to contact me or become my Facebook friend: Click here

 Top of Page HomeMembers Tutorials Forum iSnapChat Contact Us 
 All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.