Posted By

Winkyboy on 11/03/09


Tagged

form post TextField onfocus as3 Onblur FocusEvent


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

damarev
tspitzr


AS3 Form Field focus/blur functions


 / 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.

  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
Posted By: knalle on November 4, 2009

nice :) gotta try it in one of my next projects

You need to login to post a comment.