AS3 Form Field focus/blur functions


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

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.


Copy this code and paste it in your HTML
  1. with (PATHTO.YOURTEXTFIELD_INSTANCE_NAME) {
  2. addEventListener(FocusEvent.FOCUS_IN, focusField);
  3. addEventListener(FocusEvent.FOCUS_OUT, blurField);
  4. }
  5.  
  6. private function focusField(e:Event) {
  7. switch (e.currentTarget.name) {
  8. case "YOURTEXTFIELD_INSTANCE_NAME" :
  9. if(e.currentTarget.text == "YOUR DEFAULT MESSAGE") e.currentTarget.text = "";
  10. break;
  11.  
  12. }
  13. }
  14. private function blurField(e:Event) {
  15. switch (e.currentTarget.name) {
  16. case "YOURTEXTFIELD_INSTANCE_NAME" :
  17. if(e.currentTarget.text == "") e.currentTarget.text = "YOUR DEFAULT MESSAGE";
  18. break;
  19.  
  20. }
  21. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.