AS: Forms 2006-03-16 20:41:11

AS: Main, yep, again.

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:


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...

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"});
//Again, dont lose this array. I'll keep using it.

Then, provide the comboBox of the array. With dataProvider.

_root.combobox.dataProvider = ng_array;
// 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);
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...


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(){

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.

//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;

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.
trace("grid: " + selectedGridRow);
} else{
trace("You no select grid. You suck");

Thats just how to read t3h datagrid. :P

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}

Response to AS: Forms 2006-03-16 20:42:43

Now, onto sending data and getting more data back

This is just about loadVars, because thats just how you deal with sending data. This is how we do it, using the previous tutorial, lets create a textfield.

button.onRelease = function(){
var data:object = new LoadVars();

Now, lets add the text fields (non components)

toDfBlaze = new LoadVars();
fromDfBlaze = new LoadVars();
//when user clicks on the text field, the text there disappears.
dfblaze_txt.onSetFocus = function(){
button.onPress = function(){
toDfBlaze = dfblaze_txt.text;
dfblaze_txt.text = "loading...";
fromDfBlaze.onLoad = function(){
dfblaze_txt.text = this.newName;

Ok, OK! Calm down, im throwing a couple of things to you at once (houses! watch out!), get a glass of water if you must. ;)

We first just created two loadVar objects, then we wait until the user clicks the button. Then we add a variable to one of the loadVars object, which is the text in the textbox. We let the player or user know that something is happening, by changing the text to LOADING. Then we do ... the sendAndLoad thingy. Which takes the data from toDfBlaze object, and sends it to lol.php3, which i suppose does something with THAT data. Any information that has to come back, is placed on the fromDfBlaze object.

So, i kinda like guess this is everything ?? =P Hope this helps for something. This is all simple for like, scoreboards. Which i have no idea how to make, ive got very limited knowledge in php, so, bleah.

Just hope this helped a bit. ;)

<3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3

Response to AS: Forms 2006-03-16 20:58:52

another nice tut, im'a go try this out now :D

Response to AS: Forms 2006-03-16 21:03:33

At 3/16/06 08:58 PM, Neashir wrote: another nice tut, im'a go try this out now :D

Thanks. ;)

Response to AS: Forms 2006-03-16 22:16:21

Example? I dont want to learn all of this if I dont like the results because I am lazy and dont want to waste 10 mintues doing this.

Response to AS: Forms 2006-03-16 22:17:28

Nice tut =). Seems pretty useful

Response to AS: Forms 2006-03-17 02:23:04

*bump* because this is useful information. and because you used me in the array ^_^ :P

========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

Response to AS: Forms 2006-03-17 15:47:45

At 3/16/06 10:16 PM, pyro111 wrote: Example? I dont want to learn all of this if I dont like the results because I am lazy and dont want to waste 10 mintues doing this.

An example? Its just a basic way of reading stuff in components, and sending it to servers. You dont need an example.

At 3/16/06 10:17 PM, True_Darkness wrote: Nice tut =). Seems pretty useful

=D Thanks.

At 3/17/06 02:23 AM, -Vengeance- wrote: *bump* because this is useful information. and because you used me in the array ^_^ :P

You ARE in the array, you silly. ;)

Response to AS: Forms 2006-03-17 16:23:07

At 3/17/06 03:57 PM, -Reedo11- wrote: Awesome tut, could you use the forms like highscore boards?

Yep, its sending AND Loading variables, and on the php page you do what it takes with them. Problem is, i dont know php, otherwise id cover it further.

Response to AS: Forms 2006-04-01 04:37:50

you should have put a ink to As: Flash + PHP shazwoogle