# TextField prototype

**URL:** <https://forum.kirupa.com/t/textfield-prototype/57856>\
**Category:** flash\
**Created:** [July 16, 2004, 7:36pm UTC](https://forum.kirupa.com/t/textfield-prototype/57856 "2004-07-16T19:36:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![originate](https://avatars.discourse-cdn.com/v4/letter/o/f04885/32.png) [@originate](https://forum.kirupa.com/u/originate)\
**Post date:** [July 16, 2004, 7:36pm UTC](https://forum.kirupa.com/t/textfield-prototype/57856/1 "2004-07-16T19:36:53Z")

</div>

protoypes are rubbing me bad. Maybe one of you may be able to assist me.

TextField.prototype.onSetFocus = function() {  
this.borderColor = focus\_border;  
this.backgroundColor = focus\_background;  
this.textColor = focus\_color;  
};  
TextField.prototype.onKillFocus = function() {  
this.borderColor = normal\_border;  
this.backgroundColor = normal\_background;  
this.textColor = normal\_color;  
};

sounds good right. Wrong. When I use two seperate swf’s that use the same prototype errors arise. When you unload one of the external swf’s the other textfields lose their defined formating.

Here is the entire code  
// start off with submit button dimmed  
submit\_mc.\_alpha = 40;  
// create the LoadVars objects which will be used later  
// one to send the data…  
dataSender = new LoadVars();  
// and one to recieve what comes back  
dataReceiver = new LoadVars();  
//  
// create listener for Key Object  
// this is just a U.I. thing - “wakes up” the submit button  
// when all fields have at least some content  
//  
formCheck = new Object();  
formCheck.onKeyUp = function() {  
if (name\_txt.text != ‘’ && email\_txt.text != ‘’ && subject\_txt.text != ‘’ && message\_txt.text != ‘’) {  
// clear any alert messages  
alert\_txt.text = “”;  
// enable the submit button  
submit\_mc.\_alpha = 100;  
} else {  
// remain disabled until all fields have content  
submit\_mc.\_alpha = 40;  
}  
};  
Key.addListener(formCheck);  
// #######SET STYLES FOR TEXT FIELDS#######  
// define styles for both normal and focussed  
// set hex values here that work with your site’s colors  
normal\_border = 0x666666;  
focus\_border = 0xFF9900;  
normal\_background = 0x7B6D64;  
focus\_background = 0xCCCCCC;  
normal\_color = 0x999999;  
focus\_color = 0x000000;  
// create an array containing the fields we wish to have styles applied to  
inputs = [name\_txt, email\_txt, subject\_txt, message\_txt];  
//  
// a “for in” loop now iterates through each element in the “inputs” array  
// and applies our “normal” formatting to each input text field  
//  
for (var elem in inputs) {  
inputs[elem].border = true;  
inputs[elem].borderColor = normal\_border;  
inputs[elem].background = true;  
inputs[elem].backgroundColor = normal\_background;  
inputs[elem].textColor = normal\_color;  
}  
//  
// this takes care of applying the “normal” style to each of the four input fields;  
// the following TextField prototypes handle highlighting when an input field  
// gains focus and resetting to normal when a field loses focus  
//  
// create a textField prototype to handle set and kill focus behaviors  
TextField.prototype.onSetFocus = function() {  
this.borderColor = focus\_border;  
this.backgroundColor = focus\_background;  
this.textColor = focus\_color;  
};  
TextField.prototype.onKillFocus = function() {  
this.borderColor = normal\_border;  
this.backgroundColor = normal\_background;  
this.textColor = normal\_color;  
};  
// finally: make the first field (name\_txt) selected when the movie loads  
Selection.setFocus(name\_txt);  
// DEFINE SUBMIT BUTTON BEHAVIOR  
submit\_mc.onRelease = function() {  
// final check to make sure fields are completed  
if (name\_txt.text != ‘’ && email\_txt.text != ‘’ && subject\_txt.text != ‘’ && message\_txt.text != ‘’) {  
alert\_txt.text = “”;  
// clear any previous error messages or warnings  
// advance playhead to frame 2 - the “processing” message  
\_root.play();  
// assign properties to LoadVars object created previously  
dataSender.name = name\_txt.text;  
dataSender.email = email\_txt.text;  
dataSender.subject = subject\_txt.text;  
dataSender.message = message\_txt.text;  
// callback function - how to handle what comes abck  
dataReceiver.onLoad = function() {  
if (this.response == “invalid”) {  
\_root.gotoAndStop(39);  
alert\_txt.text = “EMAIL NOT VALID.”;  
} else if (this.response == “error”) {  
\_root.gotoAndStop(41);  
} else if (this.response == “passed”) {  
\_root.gotoAndPlay(“main”);  
}  
};  
// now send data to script  
// \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
// NOTE: the line below presumes the Flash swf file and php script are in the  
// SAME DIRECTORY on your server. If this is not the case (if for example you  
// wish to put the php script along with other similar items in a “scripts”  
// directory) you MUST MODIFY THE PATH. Otherwise the Flash movie won’t be  
// able to locate the php script.  
// \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
dataSender.sendAndLoad(“processEmail.php”, dataReceiver, “POST”);  
} else {  
// warning if they try to submit before completing  
alert\_txt.text = “COMPLETE ALL FIELDS.”;  
}  
};
