Flex: Is it possible for a changewatcher to watch multiple variables?

From the Documentation, it is not possible:

“A single ChangeWatcher instance can watch one property, or a property chain. A property chain is a sequence of properties accessible from a host object. For example, the expression obj.a.b.c contains the property chain (a, b, c).”

In my case the properties are not part of the same property chain, so I cannot have a single watcher watch all of them.

However, the code can be simplified. The function to update the main variable needs to be called any time any of the dependent variables are updated. The ChangeWatchers that do this do not need to be declared or named. The ChangeWatcher declarations can be removed and the init function replaced with this one:

        public function init(event:FlexEvent):void{
            ChangeWatcher.watch(this, 'btn1Clicked', updateNClicked);
            ChangeWatcher.watch(this, 'btn2Clicked', updateNClicked);
            ChangeWatcher.watch(this, 'btn3Clicked', updateNClicked);
        }

Leave a Comment