AS Form handler


/ Published in: ActionScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /***************
  2. *
  3. * INIT FORM
  4. *
  5. **************/
  6. form = { };
  7.  
  8. /***************
  9. *** RADIOS
  10. **************/
  11. // obj : {radios:Array, value:String}
  12. function initRadio(obj:Object) {
  13. for (var i = 0; i < obj.radios.length; i++) {
  14. r = obj.radios[i];
  15. r.value = i;
  16. r.onPress = function () {
  17. // init all radios
  18. for (var j = 0; j < obj.radios.length; j++) obj.radios[j].gotoAndStop(1);
  19. this.gotoAndStop(2);
  20. obj.value = this.value;
  21. }
  22. }
  23. }
  24. // init
  25. //form.civ = {radios:[radio_civ_1, radio_civ_2], value:""};
  26. //initRadio(form.civ);
  27.  
  28. /***************
  29. *** FIELDS
  30. **************/
  31. // obj : {field:TextField, pass:Boolean, default_value:String, value:String}
  32. function initField(obj:Object) {
  33. f = obj.field;
  34. f.text = obj.default_value;
  35. f.onSetFocus = function() {
  36. if(this.text == obj.default_value) this.text = "";
  37. if(obj.pass) this.password = true;
  38. }
  39.  
  40. f.onKillFocus = function() {
  41. if(this.text == "") {
  42. this.text = obj.default_value;
  43. this.password = false;
  44. obj.value="";
  45. }
  46. else obj.value = this.text;
  47. }
  48. }
  49. // init
  50. //form.name1 = {field:txt_name1, default_value:"VOTRE PRENOM", value:""};
  51. //initField(form.name1);
  52.  
  53. /// CHECK MAIL
  54. function isMail (mailType:String):Boolean {
  55. var t:String = mailType;
  56. var tmpArray:Array = t.split("@");
  57. if (tmpArray.length != 2) return;
  58.  
  59. var tLen:Number = tmpArray[1].length;
  60. var tmpChar = tmpArray[1];
  61. var tmpCharZero = tmpArray[0].length
  62. if (tLen<2 || tmpCharZero<2) return;
  63.  
  64. for (var i:Number = tLen; i>0; i--) {
  65. if (tmpChar.charAt(i) == ".") {
  66. newPoint = i;
  67. afterDot = tmpChar.substr(newPoint, tLen);
  68. (afterDot.length>=2) ? (myValue=true) : (myValue=false);
  69. break;
  70. }
  71. }
  72. return myValue;
  73. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.