<? XML version = "1.0" encoding = "UTF-8"?> <S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009" xmlns: S = "Library: // ns.adobe.com/flex/spark" xmlns: MX = "Library: // ns.adobe.com/flex/mx" creationcomplete = "Init () "> <s: layout> <s: horizontallayout/> </S: layout> <FX: SCRIPT> <! [CDATA [import MX. binding. utils. changewatcher; import MX. controls. alert; import MX. events. flexevent; protected VaR _ watcher: changewatcher; protected function Init (): void {togglewatch ();} private function togglewatch (): void {If (_ watcher & _ watcher. iswatching () {_ watcher. unwatch (); tooglebutton. label = "watch";} else {_ watcher = changewatcher. watch (inputfiled, "text", ontextchange); tooglebutton. label = "stop watching" ;}} private function ontextchange (Event: Event): void {mylabel. TEXT = inputfiled. text;}]> </FX: SCRIPT> <s: Label id = "mylabel"/> <s: textinput id = "inputfiled" text = "Start text"/> <s: button id = "tooglebutton" label = "watch text" Click = "togglewatch () "/> </S: Application>