3.4 The rest of the code
Cancel button: this button will reset all the textfield and maked the sendButton disabled:
on (release)
{
Sname.text = ''
Semail.text = ''
Ssubject.text = ''
Smessage.text = ''
sendMC.sendButton.enabled = false;
}
- TextField functions: as you can see in the example file textfield will change their border and background color once they are focused, and comes back to their original state when unfocused.
Here the cde to do that:
// --------------------
// TextField Styles
// --------------------
normal_border = 0xCCCCCC
select_border = 0x000000
normal_background = 0xEEEEEE
select_background = 0xDDDDDD
normal_color = 0x999999
select_color = 0x666666
// ---------------------
// apply the style
// to every textfield
// ---------------------
function format_field(f)
{
for(var a in f)
{
f[a].border = true
f[a].borderColor = normal_border
f[a].background = true
f[a].backgroundColor = normal_background
f[a].textColor = normal_color
}
}
format_field([Sname,Semail,Ssubject,Smessage]);
// ---------------------
// define style change
// function for TXT
// ---------------------
TextField.prototype.onSetFocus = function()
{
this.borderColor = select_border
this.backgroundColor = select_background
this.textColor = select_color
}
TextField.prototype.onKillFocus = function()
{
this.borderColor = normal_border
this.backgroundColor = normal_background
this.textColor = normal_color
}
// set the starting focus selection
Selection.setFocus(Sname)
At first I define the two different state colors for border and background:
normal_border = 0xCCCCCC
select_border = 0x000000
normal_background = 0xEEEEEE
select_background = 0xDDDDDD
normal_color = 0x999999
select_color = 0x666666
then I've created a function that will apply the initial state color to all the textfield I pass to that function: function format_field(f)
Then I create a prototype function for Textfield object; one for the onSetFocus and another for the onKillFocus. I create a protype function only for convenience, but you can define a function for every dunamic textfield of the stage.
4. Example files & download
download .zip file with files used in this tutorial
view the example
