flash - One focus event listener for all input text field in ActionScript? -
i finished of andreas. add more code default text value of targeted text field. helps me set text of targeted field default when focus out. "andreas".
import flash.events.focusevent; import flash.text.textfield; input1.addeventlistener(focusevent.focus_in,inhand); input1.addeventlistener(focusevent.focus_out,outhand); //add other text input references did below... input2.addeventlistener(focusevent.focus_in, inhand); input2.addeventlistener(focusevent.focus_out, outhand); var def1:string = input1.text; var def2:string = input2.text; function inhand(evt:focusevent):void { var textfield:textfield = textfield(evt.target); textfield.text = ""; } function outhand(evt:focusevent):void { var textfield:textfield = textfield(evt.target); if(textfield.text == "") { switch(textfield.name) { case "input1": textfield.text = def1; break; case "input2": textfield.text = def2; break; default: break; } } }
yes, referring displayobject provided in focusevent, can obtain reference hovered object. allows create generic references object being hovered, allowing place on many textfields want.
import flash.events.focusevent; import flash.text.textfield; input1.addeventlistener(focusevent.focus_in,inhand); input1.addeventlistener(focusevent.focus_out,outhand); //add other text input references did below... input2.addeventlistener(focusevent.focus_in, inhand); input2.addeventlistener(focusevent.focus_out, outhand); var def1:string = "your text value here"; function inhand(evt:focusevent):void { var textfield:textfield = textfield(evt.target); textfield.text = ""; } function outhand(evt:focusevent):void { var textfield:textfield = textfield(evt.target); if(textfield.text == "") { textfield.text = def1; } }
Comments
Post a Comment