How to use ASForms

April 5th, 2006 by ae

ASFormsASForms FAQ | Download ASForms | How to use ASForms

 

 

 

 

Using ASForms is fairly simple – especially if you have ever used html forms before as its the same principal. For each form you need to add a ‘element’ which consists of an id and a label.

For example if I wanted to add a checkbox I would do this:


// add checkbox with id 'p' and label Papadums
var checkbox:Checkbox = new Checkbox(_root, "indianDelights", 123);
checkbox.addFormElement("p", "Papadums");
checkbox.setPos(50, 50); // set the position of the checkbox (x,y values)
checkbox.render(); // draw the checkbox

If you wanted to change a form (perhaps because of an event), you can easy add another form element or remove one, as long as you render the movieclip again:


// add another couple of checkboxes
checkbox.addFormElement("n", "Naan");
checkbox.addFormElement("r", "Raita");
checkbox.render(); // when this draws there will be three checkboxes: Papadums, Naan, Raita

Remove an item:


// remove Naan
checkbox.removeFormItem("Naan");
checkbox.render(); // when this draws there will be two checkboxes: Papadums, Raita

To get the selected values from the form is easy:


// get the results from the checkboxes
var resultsArray:Array = checkbox.getSelected();
trace(resultsArray); // this will display an array of the checkboxes that are selected (eg. n,r)
// note that it only displays the id - not the label

One thing to note is that the results are always returned in a array – even for text inputs and radios. In this case you just grab the first element of the array – getSelected()[0] :


// get the results from the radioboxes
var radioBoxesResult:String = radioBoxes.getSelected()[0];
trace(radioBoxesResult); // output: someId
// note that it only displays the id - not the label

More to come…

I’ll keep adding to this. But will make an effort to add code in the next few days explaining:

  • The simple event management built in
  • How the skins work
  • All the available methods and functions and what they do and do not
  • How to implement buttons[code to come]
  • No Comments » Comments to this post

    Leave a Reply