<mySearch ⁄>
<mySnippets order="rand" ⁄>
<myContacts ⁄><email ⁄>
<windows live messenger ⁄>
<myCurriculum type="pdf" ⁄>
<myBlog show="last" ⁄>
<myNews show="rand" ⁄>
<myNews type="cat" ⁄>
<myQuote order="random" ⁄>A leveza triunfa da dureza; a fraqueza, da força.
<myPhoto order="random" ⁄>
<myAdSense ⁄>
<myVisitorsMap ⁄>
/** * This class will create form field default captions * * @author pedrocorreia.net */ class FormFieldDefaults { private var $this:Object; private var $path:Object; private var fields:Object; /** * Constructor * * @param Object Field defaults * @param Object Form "this" * @param Object Path to Form */ public function FormFieldDefaults(_fields:Object, _this:Object, _path:Object) { this.$this = _this; this.$path = _path; this.fields = _fields; if (typeof String.prototype.trim !== "function") { /** * String trim prototype */ String.prototype.trim = function() { for(var i = 0; this.charCodeAt(i) < 33; i++); for(var j = this.length-1; this.charCodeAt(j) < 33; j--); return this.substring(i, j+1); }; } } //end constructor FormFieldDefaults /** * Reset Form to its defaults */ public function Reset():Void { for (var field in this.fields) { this.$path[field].text = this.fields[field]; } } //end ResetValues /** * Clear default values */ public function Clear():Void { for (var field in this.fields) { if (this.$path[field].text === this.fields[field]) { this.$path[field].text = ""; } } } //end ClearDefaultValues /** * Create and manage Event Handlers */ public function EventHandlers():Void { /** * EventHandler onFieldFocus */ var //cache FormFieldDefaults "this" $self = this, /** * EventHandler onSetFocus * * @param Object */ __onSetFocus = function(e:Object):Void{ if (e.text.length > 0 && e.text === $self.fields[e._name]) { e.text = ""; } }, //end __onSetFocus /** * EventHandler onKillFocus * * @param Object */ __onKillFocus = function(e:Object):Void { if (e.text.trim() === "") { e.text = $self.fields[e._name]; } }, //end __onKillFocus /** * Create an EventHandler * * @param String Name * @param String Event Name * @param Function Callback */ _CreateEvent = function(obj:String, evt:String, callback:Function):Void { $self.$path[obj]["on" + evt] = callback; }, /** * Iterate fields Object and * add field EventHandlers */ _SetEventHandlers = function():Void { for (var field in $self.fields) { //Add EventHandler Field on Focus _CreateEvent(field, "SetFocus", function():Void{ __onSetFocus(this); }); //Add EventHandler Field on Lost Focus _CreateEvent(field, "KillFocus", function():Void{ __onKillFocus(this); }); } //end $self.fields for }; //end _SetEventHandlers _SetEventHandlers(); } //end EventHandlers /** * Startup function * * Fill form with default values; * Add Event Handlers to form textbox fields */ public function Init():Void { this.Reset(); this.EventHandlers(); } //end Init } //end FormFieldDefaults class
//used when loading as external swf, it's not strictly necessary, //however it could save you a few headaches with paths ^_^'' _root._lockroot = true; //disable focus around textbox _root._focusrect = false; var //cache our current "this" $self = this, //save path to form, in this example it's the same, however it could be different, //for instance, our form could be inside a MovieClip, in this case it would be //$path = $self.myMovieClipName; $path = $self, /** * Auxiliary function to add an EventHandler * * @param String Name * @param String Event Name * @param Function Callback Function */ CreateEvent = function(obj:String, evt:String, callback:Function) { $path[obj]["on" + evt] = callback; }, /** * Form field default values * Object => { field_name: "default field value" } */ field_defaults:Object = { txt_name: "Your name", txt_email: "You e-mail address" }, //create our object frm_defaults = new FormFieldDefaults(field_defaults, $self, $path); //initialize our script, basically it'll reset the form values and //add all event handlers frm_defaults.Init(); //create event for submit the form CreateEvent ("bt_send", "Release", function() { //clear all default fields left blank frm_defaults.Clear(); //here goes your submit code ... // ..... }); //create event for reset the form CreateEvent ("bt_reset", "Release", function() { frm_defaults.Reset(); });