PDA

View Full Version : ChangeWatcher not working with TabNavigator ?


miraceti
09-25-2007, 11:34 AM
I try to figure out why binding does not work in my application. During the search I noticed an Adobe livedocs example (http://livedocs.adobe.com/flex/2/docs/00001044.html) of ChangeWatcher class, which helps debugging binding.

I even simplified this example and then there are two cases:
1. everything works OK (watcherListener is called)
2. if only a <mx:TabNavigator> is added to wrap the VBox, watcherListener is no more working

Below is the simpified code WITH <mx:TabNavigator>. After launching this application, any change to the top TextInput does not launch the watcher. Binding takes place but watcher does not launch. After removing the <mx:TabNavigator> wrapper, changes to the top TextInput does launch the watcher.

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="initWatcher();">
<mx:Script>
<![CDATA[
import mx.binding.utils.ChangeWatcher;
import mx.events.FlexEvent;
// Define binding watcher.
public function initWatcher():void {
// Define a watcher for the text binding.
ChangeWatcher.watch(textarea, "text", watcherListener);
}
// Event listener when binding occurs.
public function watcherListener(event:Event):void {
myTA1.text="binding occurred";
}
]]>
</mx:Script>
<mx:Panel >
<mx:TabNavigator>
<mx:VBox >
<!-- Define a binding expression to watch. -->
<mx:TextInput id="textinput" text="Hello"/>
<mx:TextArea id="textarea" text="{textinput.text}"/>
<mx:TextArea id="myTA1"/>
</mx:VBox>
</mx:TabNavigator>
</mx:Panel>
</mx:Application>

Why is that? How to define this watcherListener to still work with the TabNavigator ?

drkstr
09-25-2007, 09:03 PM
Yeah, bindings work kind of funky with "view stack" like containers. I am not sure why, but maybe playing with the creationPolicy property will help. I just used a call to someControlWithBinding.executeBindings() when the tab changes and it seemed to work ok. Not sure if this will work in your instance though.

Best Regards,
...aaeon