/ Published in: ActionScript 3
Paste this into your AS file to add focus and blur events to your text/form fields. If your field contains YOUR DEFAULT MESSAGE when focus is brought to it, it will erase itself, to be ready for text entry. If focus is lost while the field is completely empty, the default message will return.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
with (PATHTO.YOURTEXTFIELD_INSTANCE_NAME) { addEventListener(FocusEvent.FOCUS_IN, focusField); addEventListener(FocusEvent.FOCUS_OUT, blurField); } private function focusField(e:Event) { switch (e.currentTarget.name) { case "YOURTEXTFIELD_INSTANCE_NAME" : if(e.currentTarget.text == "YOUR DEFAULT MESSAGE") e.currentTarget.text = ""; break; } } private function blurField(e:Event) { switch (e.currentTarget.name) { case "YOURTEXTFIELD_INSTANCE_NAME" : if(e.currentTarget.text == "") e.currentTarget.text = "YOUR DEFAULT MESSAGE"; break; } }