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();
}
}

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1. Contact Blog Owner