Posts Tagged ‘TabbedNavigator’

ValidatorForm as a base class and in a TabbedNavigator

Wednesday, July 9th, 2008

I had trouble using ValidatorForm as the base tag for Form components, and still more trouble when I used those in a TabNavigator. In both cases, the fault was in trying to refer to add a CHANGE event listener to the as-yet null {source} for the validators.

The solution to the first part was to pull the meat out of the validators() setter and into an assignValidators() function, saving the array of validators to a private _validators for later use in calling assignValidators() from creationComplete(). This worked until I used the ValidatorForm in a TabbedNavigator, which doesn’t create its grandchildren – our {source} – until the tab is activated (or unless you set creationPolicy=’all’, but a component just shouldn’t make you do that). The solution here is to use callLater(assignValidators) in creationComplete() instead of just assignValidators().

Here’s the source, and what changed:

      private var _validators: Array;
        public function set validators(validators:Array):void  { 
          _validators = validators; 
        }
        
        public function get validators(): Array {
          return _validators;
        }
        
        protected function creationComplete(): void {
              callLater(assignValidators);
        }
        
        private function assignValidators(): void {
        
            for(var i:uint=0; i < validators.length; i++) { ...