THIS LITTLE BITCH IS TWO POSTS, SO LET ME POST THE OTHER ONE, ITS NOT LONG... K I really wanna see if this is helpful at all. xD
First off, youll need basic knowledge on components, variables, and attaching MCs.
Lol, wut will i learn now.
This time, we'll go over how to create a Form, how to submit data and get it back. How to add components (
Look over components, here) to the form, using them, and even creating a form from scratch.
First off Two Ways To Add Components
There, i believe, are two ways to add components onto your flash file. Which are:
createClassObject();
attachMovie();
I believe you SHOULD already know what attachMovie is about, so, i wont go over it.
Both of the above ways require that the component is already in your library (drag n drop to stage, then delete it). This means, that you cant create a component dinamically, with magic. No magic here sir.
Adding a component with createClassObject();
At some point in its own life, createClassObject() is literally the same as attachMovie, who knows why people even created it. =P IF you have no REAL idea of what a class is, i suggest you to get out of here and look for a class tutorial, ill cover it VERY simple in this tutorial, so, go get more knowledge before coming, or youll hurt yourself. Really.
For a checkbox...
this.createClassObject(mx.controls.CheckBo
x,"cb",1{label:"ROFL Check Box"});
The only real difference, is that instead of using the symbols ID, we use the class name. Somehow, the actionscripting manual wants US to use createClassObject rather than attachMovie for components, for unknown reasons though.
ok, now, Actual forms
Creating forms from scratch is just... stupid. So im guessing youll use components, thing is, how do i send variables or receive info from any where ?
Ok, ill assume you went over and read my components tutorial, and you know how to use dataProvider to fill in comboboxes or whatever the cheese you want. (mmm... cheese), ok, no cheese. Lets go with comboboxes.
Hmm, silly comboboxes. Ok, lets create a small array of stuff..
//creating an array
var ng_array:Array = new Array();
ng_array.push({data:"",label:"Choose an user"});
ng_array.push({data:"df",label:"Darkfire_B
laze"});
ng_array.push({data:"ab",label:"Authorblue
s"});
ng_array.push({data:"vg",label:"Vengeance"
});
ng_array.push({data:"fx",label:"Fenix"});
//Again, dont lose this array. I'll keep using it.
Then, provide the comboBox of the array. With dataProvider.
_root.combobox.dataProvider = ng_array;
_root.combobox.setSize(150,22);
// im assuming you know the above.
Now, onto actual STUFF. Reading in stuff from components, like... from this above combobox, would look like:
button.onRelease = function()
{
//finding out what the user chose as user on the combo box
if(combobox. selectedItem.data!="")
{
trace("User chose: " + combobox. selectedItem.label);
}
else
{
trace("lol, choose something or i kill j00");
}
}
//notice that im using spaces just for the line to not break, its supposed to go all together.
The thing you should care in here is the selectedItem. Thats the thing that finds which item was chose from the drop down menu. You can also use selectedIndex, which returns the index of the selected item. First item is 0, second is 1, and so on.
Lets go a bit further on that above code, that is checking if the selected item's data ISNT blank, ("" means blank, its just opening and closing the quotes, with no text). You get the idea, i believe.
Reading from an EDITABLE combo Box
To make a comboBox editable, you just do...
combobox.editable=true;
This cleans out the combo text field, so the user can now type in it. How would you get THAT value? selectedItem or selectedIndex wont do any good, as soon as you say that its editable, youre like, screwed up. Those properties wont work. They become "undefined". To get what the user inputs, you must use this piece of shi-- i mean code.
button.onRelease = function(){
trace(combobox.value);
}
Thats the only way youll get a value of an editable component, with the value property. This can also be useful in a non editable combo box.
<Note>Checkboxes are like the same, but you use "selected" instead of selectedItem or selectedIndex, its easier with checkboxes.</Note>
Now, radio Buttons are another thing...you use getValue, instead of value, or selectedItem or Index, they wont work. You can make a radio button "unabled" too, just because you obvously feel like it.
radiobutton.setEnabled(false);
//easy, as, pai.
Reading from a DataGrid
This one is a little bit triickier, but its still like the same. First, we have to attach a listener to it to see when somebody clicks on a cell.
//setting up variables
var gridSelected:Boolean;
var selectedGridRow:Number;
Then, we just use the same old array. To provide it with some silly data.
grid.dataProvider = ng_array;
Finally, we check to see what row has been selected.
gridListener = new Object();
gridListener.cellPress = function(evt){
gridSelected = true;
selectedGridRow = grid.getItemAt(evt.itemIndex).label;
}
grid.addEventListener("cellPress",gridList
ener);
Holy fuxxors, what is this?
This is a listener, and an event handler, its not too complicated...
When an event happens, all that information about the event-what it was, what object it happened to, where on the stage, etc- is passed to the event handler, thats what evt IS. The event objet that has all the information. In this case, the event happened to our grid.
Finally, to validate the data itself:
//validating the grid, making sure what is selected.
if(gridSelected){
trace("grid: " + selectedGridRow);
} else{
trace("You no select grid. You suck");
}
Thats just how to read t3h datagrid. :P
TextBoxes
Seeing that im nearly out of characters, and i dont wanna be bothered with another post, you read that info with either, text or length. To see if something hasnt been typed in:
if(!mytext.text){//blah}
if(mytext.text == ""){//blah}
if(mytext.length==0){//blah}