Binding in Flex via Actionscript

Posted: September 17, 2008 in Flex

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s