Input, Process and Output - 02textIO.fla
This program demonstrates
- Input -
some text typed by the user.
button press to trigger the processing
- Process - joining text strings together.
- Output - text output to the screen.
It makes use of
- an initialisation script
- static text for output
- input text
- button release event handling
- dynamic text for output
|
Start up Macromedia Flash
- Start a new Flash document.
- Set the background colour.
- Set the size of the stage to 250 x 160.
- Save this document as 02textIO.fla
|
|
Add a Static Text title to the stage.
- Select the text tool and drag out a rectangle where you can enter
some text onto the stage.
The text should read "What is your name?".
- Select the arrow tool and drag the text to the right position on the
stage.
- Make sure the text is static.
|
|
Add an Input Text control to your stage.
- Select the text tool and drag out a rectangle where you can enter
some text onto the stage.
- Set the text to Input Text
- Select the arrow tool and drag the text to the right position on the
stage.
- Set the Instance Name of the text to "inputText"
- Toggle the text border on.
|
|
Add a push button to the stage.
CTRL+F7 toggles the Components frame on or off.
- Double click here to add the push button
- Select the arrow tool and drag the button to the correct position.
- Make sure the Parameters pane is selected.
- Alter the button label to "Submit".
|
|
Add a Dynamic Text area for the program output.
- Select the text tool and drag out an area for the output text.
- (a) Make sure the text is Dynamic and
(b) give it an instance name of outputText.
- Select the arrow tool and drag the output text to the correct position.
- Toggle the text border off.
|
|
It is good coding practice to initialise your data properly. Write some ActionScript code to initialise the Input Text
to read "Who are you?".
- Click on Layer 1 - Frame 1.
- Click Actions to open this view.
- You can turn line numbers on or off here.
- Enter this code
_root.inputText.text = "Enter your name here. ";
- Use CTRL+Enter to do a test run.
|
|
Create the event handler to process the button release.
- Click the Submit Button and make sure it is selected (and nothing
else is selected).
- Click Actions to open this view.
- Enter your code here ...
on (release)
{
_root.outputText.text = "Hello " + _root.inputText.text;
}
- Remember to save your work.
Do a test run with CTRL+Enter. The program should now work. |
|
Here is the finished movie/program.
You can download the source code. |
To run the program again, refresh your display
(F5 key with Internet Explorer)
|
Your learning task
Write your own version of this program.
Add to it to ask "where do you live?". Assuming your name is
Fred and you live in Norwich, the program should produce output like this
...
"Hello Fred from Norwich." |
|
© C N Bauers (2004) - You may use these materials for your self education.
Educational institutions may use these materials too.