Binding in Flex via Actionscript

Here’s an example I created to bind a text field with a label. This needs to be done with you are dynamically creating components inside of your app instead of using MXML. Be sure to use the if statement on the unwatch function to avoid an error for null pointing.

private var watcher:ChangeWatcher;

private function watch():void {
var SampleLabel:Label = new Label();
SampleHBox.addChild(SampleLabel);
watcher = BindingUtils.bindProperty(SampleLabel,"text", sampleText,"text");
}

private function unwatch():void {
if (watcher != null) {
watcher.unwatch();
}
}