Forked from: actionscriptbible's Chapter 17 Example 7 diff:35 Chapter 17 Example 8 actionscript.. forked:2favorite:0lines:63license : MIT License modified : 2009-06-29 09:38:28 Embed Tweet package { import flash.display.Sprite; import flash.events.FocusEvent; import flash.text.TextField; import flash.text.TextFieldType; import flash.text.TextFormat; import flash.utils.Dictionary; public class ch17ex8 extends Sprite { protected const INFMT:TextFormat = new TextFormat("_sans", 12, 0, true); protected const OUTFMT:TextFormat = new TextFormat("_sans", 12, 0x808080, false); protected var prompts:Dictionary; protected var nameTF:TextField; protected var phoneTF:TextField; protected var emailTF:TextField; public function ch17ex8() { prompts = new Dictionary(); nameTF = makeInputTextField(); nameTF.text = "Your name"; nameTF.setTextFormat(OUTFMT); nameTF.maxChars = 40; prompts[nameTF] = nameTF.text; phoneTF = makeInputTextField(); phoneTF.text = "Your phone number"; phoneTF.setTextFormat(OUTFMT); phoneTF.maxChars = 20; phoneTF.restrict = "0-9()\\-"; prompts[phoneTF] = phoneTF.text; emailTF = makeInputTextField(); emailTF.text = "Your email address"; emailTF.setTextFormat(OUTFMT); emailTF.maxChars = 40; emailTF.restrict = "a-zA-Z0-9_\\-+=~!@#$%\\^."; prompts[emailTF] = emailTF.text; } protected function onFocusIn(event:FocusEvent):void { var tf:TextField = TextField(event.target); if (tf.text == prompts[tf]) { tf.text = ""; } tf.setTextFormat(INFMT); tf.defaultTextFormat = INFMT; } protected function onFocusOut(event:FocusEvent):void { var tf:TextField = TextField(event.target); if (tf.text == "") { tf.text = prompts[tf]; tf.setTextFormat(OUTFMT); } } protected function makeInputTextField():TextField { var tf:TextField = new TextField(); tf.type = TextFieldType.INPUT; tf.border = true; tf.width = 300; tf.height = 18; tf.y = numChildren * 26; tf.addEventListener(FocusEvent.FOCUS_IN, onFocusIn); tf.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut); addChild(tf); return tf; } } } Code Fullscreen Preview Fullscreen as3bible FocusEvent Dictionary type FocusEvent.FOCUS_IN FocusEvent.FOCUS_OUT target TextFormat numChildren addEventListener height width text addChild Sprite sort new page view favorite forked pv78 forked from: Chapter 17 Exampl.. Adam.Sikora forked:0 favorite:0lines:63 (diff:1) pv815 Chapter 17 Example 9 actionscriptbible forked:4 favorite:0lines:110 (diff:64) tag: as3bible