This is an archived tutorial from the kirupa.com legacy collection. It covers software that may no longer be available, but it is kept online because the ideas still hold up.
This tutorial is more or less a sequel to
Kirupa's tutorial about the
scrollbar and mine about the
listbox. Please read them carefully before attempting this one.
I will show you in this tutorial how to:
We are going to make a form asking for information about the user. He will
answer a certain number of questions, and when he presses the submit button,
we will get all his answers, and go to an answer frame that processes the input data.
This is what the form is going to look like when everything is finished:
[ fill the form and press the submit button ]
To see more easily how it works, we are going to use the trace function to display in the output window what the users inputs.
Creating the form:

[ the
timeline ]

[ the
timeline again ]
Drag and drop a radio button in the top left end of the scene. Then press Ctrl and drag it to duplicate it. Do it once more to have 3 radio buttons.
Drag and drop a combobox on the scene under the radio buttons.
Drag and drop a listbox.
Drag and drop two push buttons.
Drag and drop a check box and then duplicate it 5 times like we did with the radio buttons.
Put an input text and drag and drop the scrollbar component on it.
This is pretty much how the form is going to look like so try and make it look good. Personally I use the properties panel all the time to place precisely my objects on the scene.
What we have to do now is populate the components, and get the input of the user. We will do this with Actionscript. Click the next section link to proceed with adding the Actionscript.
|
|
This page will include Actionscript and related information.
If you have not completed page one of this tutorial,
click here.
// The display function
function radioDisplay (component) {
radio = component.getValue() ;
trace ( radio ) ;
}
// We assign this function to the group gender
gender.setChangeHandler ("radioDisplay") ;
[ hum... how does this work ? ]
This is quite simple really, and it looks like what we did in the listbox tutorial. First we define a function, radioDisplay, that will trace the selected button:
function radioDisplay (component) { radio = component.getValue() ;
The function takes as an argument the component to which
we are going to apply it. The getValue() method gets the
selected radio button in a group, that is to say exactly what we
want. We trace it to see it more clearly. Save your work and test the animation.
// populate the combobox
for (i=1970;i<1990;i++) {
birth.addItem (i) ;
}
// function to display the selection
function comboDisplay (component) {
combo = component.getSelectedItem().label ;
trace ( combo );
}
// We assign the function to the combobox
birth.setChangeHandler ("comboDisplay") ;
[ looks familiar ? ]
birth.addItem (i); combo = component.getSelectedItem().label ;
First we introduce the addItem() method, which adds an item to the combobox. Simple enough. The rest is the same as previously, except we use the getSelectedItem() method, equivalent to the getValue() method. One last thing, this method returns the label and the data of the Item selected, but all we want is the label, hence the .label syntax.
// The labels in the listbox
myLabels = new Array ("France", "US", "Germany", "New Zealand", "England", "China", "Japan", "Singapore", "Australia", "Dark side of the moon");
// Populate the listbox
for (i in myLabels) {
country.addItem (myLabels[i]) ;
}
// Display function
function listDisplay (component) {
list = component.getSelectedItem().label ;
trace ( list ) ;
}
// You get the picture
country.setChangeHandler ("listDisplay") ;
I'm sure you can see that it's exactly the same thing as previously. If you want to add elements in your listbox, all you have to do is put them in the array myLabels.
Basically, what we do here is check the status of all the checkboxes whenever the user checks one of them.
for(j in myCheck){ if(myCheck[j].getValue()) s += myCheck[j].getLabel()+"\n"; ((s.length) ? s : "Nothing"));
1st line: j will take the values 0, 1, 2, 3, 4 (because there are 5 elements in our array).
2nd line: if the box we are currently looking at is checked, we put it's label in the string s
3rd line: we trace the string s only if there is something in it. A?B:C; means if A is true then do B, else do C.
// The textarea is empty, so no scrollbar
_root.bar._visible=false;
// onChanged function
comment.onChanged = function(){
if (this.maxscroll>1) {
_root.bar._visible=true;
}
else _root.bar._visible=false;
}
_root.bar._visible=false;
When the movie loads, there is nothing in the text area, so there's no need for a scrollbar. That's why we set it as invisible.
comment.onChanged = function(){ if (this.maxscroll>1) _root.bar._visible=true; else _root.bar._visible=false;
The onChanged method is not a simple method. It is quite similar to onMouseDown for instance,
and will be executed whenever the user changes something in the text.
So when the user changes something, we check the maxscoll property. If it is >1, it means
that the scroll is necessary. That's why we make the scrollbar visible.
Otherwise, we set it as invisible.
// Reset button function
onReset = function () {
// radio buttons
male.setValue(false);
female.setValue(false);
other.setValue(false);
// listbox
birth.setSelectedIndex(0);
// combobox
country.setScrollPosition(0);
country.setSelectedIndices(null);
// checkbox
var j;
for (j in myCheck) {
myCheck[j].setValue(false);
}
// text
comment.text = "";
bar._visible = false;
}
It looks complicated, but this is really simple: all I did was uncheck, empty and unselect all
the components. You can refer to Macromedia's Actionscript Dictionary to see all the Components
methods.
Now the onSubmit should be a walk in the park. We have all the information, so it will just
take us to the frame labelled result (and get the input text).
onSubmit=function(){ texte=comment.text ; _root.gotoAndStop("result"); }
The complete code in frame 1 is:
stop() ;
// 1. Radion buttons
// -----------------
// The display function
function radioDisplay (component) {
radio = component.getValue() ;
}
// We assign this function to the group gender
gender.setChangeHandler ("radioDisplay") ;
// 2. Combobox
// -----------
// populate the combobox
for (i=1970;i<1990;i++) {
birth.addItem (i) ;
}
// function to display the selection
function comboDisplay (component) {
combo = component.getSelectedItem().label ;
}
// We assign the function to the combobox
birth.setChangeHandler ("comboDisplay") ;
// 3. Listbox
// ----------
// The labels in the listbox
myLabels = new Array ("France","US","Germany","New Zealand","England","China","Japan","Singapore","Australia","Dark side of the moon");
// Populate the listbox
for (i=0;i<myLabels.length;i++) {
country.addItem (myLabels[i]) ;
}
// Display function
function listDisplay (component) {
list = component.getSelectedItem().label ;
}
// You get the picture
country.setChangeHandler ("listDisplay") ;
// 4. Checkbox
// -----------
// Array of the instance names of the checkboxes
myCheck = [flash,games,beer,sport,art];
// Function
function checkDisplay(component) {
var j,s;
for(j in myCheck){
if(myCheck[j].getValue()) s += myCheck[j].getLabel()+"\n";
}
checke = "You like: " + ((s.length) ? s : "Nothing");
}
// As usual...
for (i=0;i<myCheck.length;i++) {
myCheck[i].setChangeHandler ("checkDisplay") ;
}
// 5. Scrollbar
// ------------
// The textarea is empty, so no scrollbar
_root.bar._visible=false;
// onChanged function
comment.onChanged = function(){
if (this.maxscroll>1) {
_root.bar._visible=true;
}
else _root.bar._visible=false;
}
// 6. Push Buttons
// ---------------
// Reset button function
onReset = function () {
// radio buttons
male.setValue(false);
female.setValue(false);
other.setValue(false);
// listbox
birth.setSelectedIndex(0);
// combobox
country.setScrollPosition(0);
country.setSelectedIndices(null);
// checkbox
var j;
for (j in myCheck) {
myCheck[j].setValue(false);
}
// text
comment.text = "";
bar._visible = false;
}
// Submit button function
onSubmit = function () {
texte = comment.text;
_root.gotoAndStop ("result");
}
Now insert a blank keyframe on frame 5 of the Component layer. Then put a dynamic text (a big one) that you will call result. Set it as multiline. We are going to put all the data coming from our components in there.
We have defined the variables radio, list, combo, checke and texte in the first frame. All we have to do is print them in the result frame (full code):
stop();
result.text = "You are a "+radio+"\n";
result.text+= "You are from "+list+"\n";
result.text+= "You were born in "+combo+"\n";
result.text+= checke;
result.text+= "You wrote a nice word for us:\n"+texte;
There !!! The form should be working now. But it's not over...
Flash MX has this wonderful new feature: you can "skin" your components, either using the skins provided by Macromedia, either by defining your own values. This is what we are going to see here. The object we will use is FStyleFormat(), or globalStyleFormet() if you want all your components to be affected by the style sheet.
// New style sheet
pomStyle = new FStyleFormat();
// Attributes of the style sheet
pomStyle.face = 0xffCC33;
pomStyle.background = 0xFFCC33;
pomStyle.arrow = 0x000000;
pomStyle.scrollTrack = 0xFFCC33;
pomStyle.highlight = 0xffcc33;
pomStyle.darkshadow = 0xffcc33;
pomStyle.selection = 0x993300;
pomStyle.textColor = 0x999999;
Applying it to the components of our movie
Then you must register your components as listeners of this style:
// We apply pomStyle to the components
pomStyle.addListener(bar);
pomStyle.addListener(country);
pomStyle.addListener(flash);
pomStyle.addListener(games);
pomStyle.addListener(beer);
pomStyle.addListener(sport);
pomStyle.addListener(art);
pomStyle.addListener(male);
pomStyle.addListener(female);
pomStyle.addListener(other);
pomStyle.addListener(birth);
pomStyle.addListener(submit);
pomStyle.addListener(reset);There. I leave you free to modify the hexadecimal values to change the aspect of your form. You can also change the properties of the textbox, but it's not a component, so it is a little bit different.
// textbox comment.backgroundColor = 0xFFCC33;
To check out the final source for this, click the following link:
There! Over for good! I hope you enjoyed this tutorial, even though it was *a bit* long.
If you want more of this, you can check this tutorial from Macromedia
here. It also explains how to send the input to Coldfusion.
pom
![]()
Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence, ads, and algorithm-driven doodads. A huge thank you to all of you who buy kirupa's books, became a paid subscriber, watch the videos, and/or interact on the forums.
Your support keeps this site going! 😇
:: Copyright KIRUPA 2026 //--