home *** CD-ROM | disk | FTP | other *** search
/ Ice Age Fan CD 1 / CD1_Scrat.iso / flash / data / game.swf / scripts / asCode / STFinputFieldClass.as < prev    next >
Encoding:
Text File  |  2012-07-04  |  2.4 KB  |  92 lines

  1. package asCode
  2. {
  3.    import flash.display.MovieClip;
  4.    import flash.events.FocusEvent;
  5.    import flash.text.TextField;
  6.    
  7.    public class STFinputFieldClass extends MovieClip
  8.    {
  9.       public static const SELECTED:String = "SELECT";
  10.       
  11.       public var textBoxBack:MovieClip;
  12.       
  13.       public var textBox:TextField;
  14.       
  15.       private var typeOfTextField:String;
  16.       
  17.       private var errorTriggered:Boolean;
  18.       
  19.       private var defaultText:String;
  20.       
  21.       private var textContent:String;
  22.       
  23.       public function STFinputFieldClass()
  24.       {
  25.          super();
  26.       }
  27.       
  28.       public function initField(param1:String, param2:String = "text") : void
  29.       {
  30.          typeOfTextField = param2;
  31.          defaultText = textBox.text = param1;
  32.          errorTriggered = false;
  33.          textBox.addEventListener(FocusEvent.FOCUS_IN,textboxSelected,false,0,true);
  34.          textBox.addEventListener(FocusEvent.FOCUS_OUT,textboxDeselected,false,0,true);
  35.       }
  36.       
  37.       public function testForContent() : Boolean
  38.       {
  39.          var _loc1_:int = 0;
  40.          var _loc2_:int = 0;
  41.          textContent = textBox.text;
  42.          if(textContent == "" || textContent == defaultText)
  43.          {
  44.             textBox.text = defaultText;
  45.             textBoxBack.gotoAndPlay("error");
  46.             errorTriggered = true;
  47.             return false;
  48.          }
  49.          if(typeOfTextField == "email")
  50.          {
  51.             _loc1_ = int(textContent.indexOf("@"));
  52.             _loc2_ = int(textContent.indexOf("."));
  53.             if(_loc1_ > 1 && _loc2_ > 1)
  54.             {
  55.                return true;
  56.             }
  57.             textBoxBack.gotoAndPlay("error");
  58.             errorTriggered = true;
  59.             return false;
  60.          }
  61.          return true;
  62.       }
  63.       
  64.       public function reset() : void
  65.       {
  66.          textBoxBack.gotoAndPlay("reset");
  67.       }
  68.       
  69.       public function textboxDeselected(param1:FocusEvent) : void
  70.       {
  71.          if(textBox.text == "")
  72.          {
  73.             textBox.text = defaultText;
  74.          }
  75.       }
  76.       
  77.       public function textboxSelected(param1:FocusEvent) : void
  78.       {
  79.          if(textBox.text == defaultText)
  80.          {
  81.             textBox.text = "";
  82.          }
  83.          if(errorTriggered)
  84.          {
  85.             errorTriggered = false;
  86.             textBoxBack.gotoAndPlay("reset");
  87.          }
  88.       }
  89.    }
  90. }
  91.  
  92.