Inputting and Outputting variables
April 17, 2007
Concepts covered: Inputting variables, outputting variables and manipulating variablesBeing able to manage variables in Flash is a very important skill for people wanting to get into actionscript. This tutorial goes through basic inputting and outputting of variables and manipulating them.
Load up Flash and create 2 static texts field spaced apart one that says Input your name and the other that says Your name is. Underneath the Input your name text create a blank input text field that has a border around it. You do this by selecting the show border around text option.

Stick the words namebox in the instance name box just under the type of text.
Under the Your name is text create a new dynamic text box. Make sure that the font colour is black so that you see it when you are outputting. Stick the word name under the variable heading; var.
Create a new button somewhere on the stage and add the following code to it.
on (release){
name=namebox.text;
}
This code says that once the button is released the name variable will be the same as namebox which is in a text field.
Text the movie to see if it works. If everything is done correctly you should be able to input your name into the input text box and once you press the button your name appears as the dynamic text.
You could output your name properly if you want to. The trace function in Flash outputs data to the screen. Adding the trace function to the code ends up like this:
on (release){
name=namebox.text;
trace(name);
}
Notice how name is set before it is outputted to the screen? If it wasn?’t the variable would be shown as undefined.
Using the same style of programming you can make a calculator of sorts.
Create a new Flash file and add the an Input numbers to be multiplied,1st number, 2nd number and The result is static textboxes in the appropriate positions. Underneath the 1st and 2nd number titles make an input text field one which has the instance of no1 and the other with no2. Under the result title make a dynamic text field with the variable result. Create a well placed button and insert the following code into it:
on (release){
result=no1.text*no2.text;
}
The code is similar to the previous code. It sets the variable result to be what the result of multiplying the 2 inputted variables as on the buttons release. You can add trace to this one if you would like.
These basic examples can lead the way for some larger programs. You can create calculators with various buttons that change the inputted text or a form asking you to fill in your details and then showing a results page with your inputted values.
If you have any difficulty with creating these programs then I advise that you download my samples and see where you went wrong.

Tags: Tutorials, Inputting and Outputting variables, flash mx, tutorial
Posted in Tutorials |
Related Entries
- Basic Programming Structure
- Intresting shapes with the Pen tool
- Standard Signature
- DP’s Guide to Buying Your First Digital Camera
No Comments »
No comments yet.
RSS feed for comments on this post.
TrackBack URL
Leave a comment

Have you checked out my gaming personal blog yet? No! Then take a squiz:
