1 Reply Latest reply on Mar 21, 2008 7:36 PM by peterent

    createChildren of component

    alejandro52 Level 1
      I want to create a component that will be used in flex mxml. the component will have a button inside.I want to set the label of the button when i create the component in mxml(i use set and get to do that), but if i create the button in the createchildren, flex first runs the tag when i call it and then the createchildren. Is it ok to call createChildren in the constructor. Because i tried it and works fine.
        • 1. Re: createChildren of component
          peterent Level 2
          No - it is not OK to call createChildren() in the constructor. You shouldn't call createChildren() yourself. Let the Flex framework do its thing.

          Here's what you do:

          createChildren() can create the object but you won't be able to set its label there because the setter for your label property might not be called by that time.

          Instead, override commitProperties() set the label in there:

          private var _yourLabel:String;
          public function set yourLabel( value:String ) : void { _yourLabel = value; }
          public function get yourLabel() : String { return _yourLabel; }

          private var button:Button;

          override protected function createChildren() : void {
          button = new Button();

          override protected function commitProperties() : void {
          button.label = yourLabel;

          That's the correct way to do it.