/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* Create two input field on the stage with name_txt and msg_txt as a name You can also set the text format onFocus. So when nothing is filled in, it is grey and when you start typing it is black */ var defaultNameEntry:String = "fill in your name"; var defaultMessageEntry:String = "fill in your message"; name_txt.tabIndex = 0; msg_txt.tabIndex = 1; name_txt.text = defaultNameEntry; msg_txt.text = defaultMessageEntry; setupEventlisteners(); function setupEventlisteners():void { name_txt.addEventListener(FocusEvent.FOCUS_IN, focusInHandler); name_txt.addEventListener(FocusEvent.FOCUS_OUT, focusOutHandler); msg_txt.addEventListener(FocusEvent.FOCUS_IN, focusInHandler); msg_txt.addEventListener(FocusEvent.FOCUS_OUT, focusOutHandler); } function focusInHandler(e:FocusEvent):void { if (e.currentTarget.name == "name_txt") { if (e.currentTarget.text == defaultNameEntry) { e.currentTarget.text = ""; } } else { if (e.currentTarget.text == defaultMessageEntry) { e.currentTarget.text = ""; } } } function focusOutHandler(e:FocusEvent):void { if (e.currentTarget.name == "name_txt") { if (e.currentTarget.text == "") { e.currentTarget.text = defaultNameEntry; } } else { if (e.currentTarget.text == "") { e.currentTarget.text = defaultMessageEntry; } } }