Pages

Sunday, January 15, 2012

AS3: Form Verifier

A form verifier class.
package engine
{ 
 
 /**
  * @file CFormVerifier.as
  * @author Abhishek Kumar
  */
 
 import mx.controls.Alert;
 
 public class CFormVerifier
 {
  private var formItems:Array;
  
  public function CFormVerifier()
  {
   formItems = [];
  }
  
  public function push(itemId:int):void
  {
   formItems[itemId] = 1;
  }
  
  public function pop(itemId:int):void
  {
   formItems[itemId] = 0;
  }
  
  public function check(filledItems:int):Boolean
  {
   for (var i:int = 0, sum:int = 0; i < formItems.length; i++)
   {
    sum += formItems[i];
   }
   return ((sum == filledItems) ? true : false);
  }
  
  public function alert():void
  {   
   Alert.show('Please fill-up all the required fields!', 'Alert');
  }
 }
 
}

No comments:

Post a Comment