6 Replies Latest reply on May 17, 2011 2:00 AM by nikos101

    labelDisplay is null in CustomComponent

    nikos101 Level 2

      I've created a custom component where I've borrowed the code from button that sets content for a label

       

       

      public class ToggledBackground extends SkinnableComponent

       

      etc

       

       

          public function set content(value:Object):void
          {
              _content = value;
             
              // Push to the optional labelDisplay skin part
              if (labelDisplay)
                  labelDisplay.text = label;
              dispatchEvent(new Event("contentChange"));
          }

       

      [Bindable("contentChange")]

       

          public function set label(value:String):void
          {
              // label property is just a proxy to the content.
              // The content setter will dispatch the event.
              content = value;
          }

      In my mxml file I declare it as such and this the label gets set. However when I debug the n set content method the labelDisplay is null.


       

       

      <customComponents:ToggledBackground  label="1.Values"   id="arroValies" >

       

              </customComponents:ToggledBackground>

        • 1. Re: labelDisplay is null in CustomComponent
          Flex harUI Adobe Employee

          See the doc on creating custom components.  Use the lifecycle methods.

          • 2. Re: labelDisplay is null in CustomComponent
            nikos101 Level 2

            thanks but I don't see the ButtonBase (im trying to copy the label stuff) do anything when the label is set to invalidateStuff,

             

            All it appears to do is:


                        labelDisplay.text = label;
                    dispatchEvent(new Event("contentChange"));

            • 3. Re: labelDisplay is null in CustomComponent
              Flex harUI Adobe Employee

              After it checks for the existing of labelDisplay.  But if you read the doc,

              and look for where _content is also applied, you'll see how the component

              lifecycle methods are used.  Follow that pattern and you should have

              success.

              1 person found this helpful
              • 4. Re: labelDisplay is null in CustomComponent
                nikos101 Level 2

                I set a breakpoint in ButtonBase here to see what happens in my normal buttons

                 

                    public function set content(value:Object):void
                    {
                        _content = value;
                       
                        // Push to the optional labelDisplay skin part
                        if (labelDisplay)
                            labelDisplay.text = label;
                        dispatchEvent(new Event("contentChange"));
                    }

                 

                 

                but I always get labelDisplay = null in the initialise phase

                but in my normal buttons the button text does get set with the values I hardcode in MXML

                However my label value never gets set

                .


                 

                    <customComponents:ToggledBackground label="5. Risk and control" id="arrowRiskC" >


                • 5. Re: labelDisplay is null in CustomComponent
                  Flex harUI Adobe Employee

                  See commitProperties

                  • 6. Re: labelDisplay is null in CustomComponent
                    nikos101 Level 2

                    sorted, I had to add this

                     

                    override protected function partAdded(partName:String, instance:Object):void
                        {
                            super.partAdded(partName, instance);
                           
                            if (instance == labelDisplay)
                            {
                               
                               
                                // Push down to the part only if the label was explicitly set
                                if (_content !== undefined)
                                    labelDisplay.text = label;
                            }
                           
                        }

                     

                    What I dont understand is where the content setter is being called on app startup (I'm not calling it in my code) for Button or my custom component