2 Replies Latest reply on Sep 19, 2011 12:19 PM by Filmzaddict

    Extending a component which already extends a spark list ItemRenderer

    Filmzaddict Level 1

      Hello everyone,

       

      I have the following situation: Im displaying lists of very similar data objects (they extend the same parent) so in order to avoid a lot of changes to many itemrenderers (if i need to change something in the common properties) when displaying this data, i defined a spark list ItemRenderer (in MXML) which displays the common properties (file called BaseRenderer.mxml):

       

      <s:ItemRenderer>

           //in the script section i override the set data property

       

       

           //some MXML labels, checkboxes, etc

      </s:ItemRenderer>

       

       

      Then i created a specific itemrenderer which extended it (file SpecificRenderer.mxml):

       

      <model:BaseRenderer>

           //again i override the set data property

       

       

           //some ADITIONAL MXML labels, checkboxes, etc

      </model:BaseRenderer>

       

      When i run the app, and when the specific renderer is used, it works (no errors are thrown) , but it only shows the content of specific renderer, nothing from base renderer is visible. Is this the right way to do this, or do i have to override some additional stuff in my specific renderers?

       

      Thank you.

       

      One more thing, i just noticed, if i remove all MXML tags from specific renderer, the content from base renderer becomes visible, seems as if specific content overrides base content. Is there a way to add mxml tags into the specificrenderer?

        • 1. Re: Extending a component which already extends a spark list ItemRenderer
          Jason Szeto Level 3

          When you subclass an MXML defined class with another MXML defined class, the content of the base class is overridden by the content of the subclass. I suspect you were expected them to be "merged" together.

           

          Either write your item renderers using Actionscript, or put the shared content in an MXML component and reuse it in your different item renderers.

          1 person found this helpful
          • 2. Re: Extending a component which already extends a spark list ItemRenderer
            Filmzaddict Level 1

            Yes i suspected them to be merged, and you gave me a great idea. As you say this behavior is true across all mxml defined components, not just itemrenderers. I want to avoid actionscript renderers because i dont (and wont) have any performance issues anyway and i like flexibility in design view, so instead i found another solution which i slightly modified. Some spark components inherit property mxmlContent, which you can override. This is what i came up with in the end: I added the property override into specific renderer and everything is shown as expected (because base elements are merged with the ones from extended component).

             

            override public function set mxmlContent(value:Array):void {

                                                    var adding:Boolean = true;

                                                    var index:int = 0;

                                                    while (adding) {

                var element:IVisualElement = null;

                try {          element = super.getElementAt(index); } catch(e:Error) {          }

             

                if ( element != null )  {

                   value.push(element);

                   index += 1;

                   }

                else

                  adding = false;

                }

                                                    value.reverse();

                                                    super.mxmlContent = value;

            }