3 Replies Latest reply on Jul 13, 2007 6:56 PM by ntsiii

    itemRenderer as class instance

    DeusAquilus
      Is it possible to use a class instance as an itemRenderer?
      For instance, say I have something like:

      var myUIComp:UIComponent = getUIComp();
      var controlCol:DataGridColumn = new DataGridColumn();
      controlCol.itemRenderer = new ClassFactory( myUIComp );

      Where of course 'new ClassFactory( myUIComp )' does not work because ClassFactory cannot wrap an instance. Is there any way that I can get myUIComp to be used as controlCol's itemRenderer?

      -Alexi
        • 1. Re: itemRenderer as class instance
          ntsiii Level 3
          Well, I need to ask why you want to use an instance instead of the class itself. That does not make sense to my understanding. The Flex framework handles instantiating itemRenderer instances frr the supplied class.

          Tracy
          • 2. Re: itemRenderer as class instance
            DeusAquilus Level 1
            The reason I want to do this is so that I can decide properties of the itemRenderer object at runtime. Say that I want to add events to it from another class e.g.
            public var c:ComboBox = new ComboBox();
            c.addEventListener(MouseEvent.CLICK, evhandler); controlCol.itemRenderer = new SomeWrapper(c);

            So that I can easily handle those events using local methods/variables.
            Or say that I have a class producing a type of UIComponent based
            on some runtime settings and I want the result to be rendered.
            instead of doing something like

            var customComp:UIComponent = getUIComp();
            controlCol.itemRenderer = customComp;

            Where getUIComp will return either a checkbox or textfield based on other runtime conditions. The only way to do something like this now is to wrap customComp in some other object e.g:

            //where Wrapper is UIComponent or something inherited from it
            public class SomeObject extends Wrapper{
            function SomeObject(){
            var customComp:UIComponent = getUIComp();
            addChild(customComp);
            }
            }
            and then:
            controlCol.itemRenderer = new ClassFactory(SomeObject);

            This method becomes a pain when having to set compile time paramters of the renderer. Say that I have a DataGrid column whose renderer is SomeObject. Inside of the SomeObject instances in the column's rows, there are different UIComponent objects that are sized differently. I would like to increase or decrease the hight of the rows based on the size of customComp but in order to do this, I have to redraw the entire column and somehow not call the renderers again in the process (is there a remedy to this?).
            • 3. Re: itemRenderer as class instance
              ntsiii Level 3
              I do not believe you will be successful with that, as far as I understand what you are saying. Runtime row-level behaviors must be data-driven.

              Do you understand that itemRenderers are recycled when you scroll the list? They cannot have any individual behaviors that are not specified by the dataProvider item data.

              You can access values in the parent app that can let you change the behavior of all rows, but that is all.

              Tracy