Skip navigation
mbautista758
Currently Being Moderated

Is overriding commitProperties neccessary when updating Spark components?

Aug 17, 2012 11:16 PM

Tags: #flex #spark #commitproperties

I understand that when creating a custom component, it's normally best practice to defer any property changes to it by using setters/getters, setting a "dirty" flag, calling invalidateProperties(), and then letting commitProperties() handle the actual changes.

But in the case where properties only affect Spark components, wouldn't this be redundant since Spark components already defer their property changes?

For instance, say I have a custom UIComponent that contains a Spark Button and I want to expose a buttonLabel property for it that changes the label of the button:

private var _buttonLabel:String;
private var myBtn:Button;
private var _buttonLabelChanged:Boolean = false;
function set buttonLabel(lbl:String){
   _buttonLabel
= lbl;
   _buttonLabelChanged
= true;
   invalidateProperties
();
}

So then setting the buttonLabel property will then eventually trigger:

override protected function commitProperties(){
   
if(_buttonLabelChanged){
          myBtn
.label = _buttonLabel;
         _buttonLabelChanged
= false;
   
}
}

But the setter for "label" in the Spark Button class is already using an invalidation process which makes the above code pointless, yes? Or am I missing something?

 
Replies
  • Currently Being Moderated
    Aug 18, 2012 10:24 PM   in reply to mbautista758

    In the components lifecycle, properties are set before children are created so if you just tried to access myBtn in the setter it would be null and you would get an error.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points