3 Replies Latest reply on Jun 10, 2009 7:07 PM by zrowthterm

    ItemRenderer in Flex4

    Hironmay Level 4

      Hi,

       

       

      I was using new Flex 4 and trying to use Itemrenderer.

       

      So, when I use a customItemRenderer that is let's say

      <s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
              xmlns:mx="library://ns.adobe.com/flex/halo" >
              <mx:Image />
              <s:RichText width="100%" height="30" text="{data.label}" >

       

              </s:RichText>
          </s:VGroup>

       

      I can't get the data property inside it. How do I use a customItemrenderer with data inside it ?

       

       

       

      One way I can think is wrapping this code inside <s:ItemRenderer >  but even that throws an exception. Please help.

       

       

      Thanks

      Hironmay Basu

        • 1. Re: ItemRenderer in Flex4
          Glenn Ruehle Adobe Employee

          Hi Hironmay,

           

          What exception are you getting when using ItemRenderer as the root tag?

           

          If you don't need interactivity, you can use MXMLComponent as the root tag. This is just a Group that implements IDataRenderer.

           

          Glenn

          • 2. Re: ItemRenderer in Flex4
            Hironmay Level 4

            Hi,

             

            Thanks for reply. Using MXMLComponent solves the problem.

             

            But still I don't know why can't i use ItemRenderer. This is the exception I get while in UIComponent.as using ItemRenderer.

             

            private function getState(stateName:String):State
                {
                    if (!states || isBaseState(stateName))
                        return null;

             

                    // Do a simple linear search for now. This can
                    // be optimized later if needed.
                    for (var i:int = 0; i < states.length; i++)
                    {
                        if (states[i].name == stateName)
                            return states[i];
                    }

             

                    var message:String = resourceManager.getString(
                        "core", "stateUndefined", [ stateName ]);
                    throw new ArgumentError(message); ///  HERE I GET ERROR

             

                    return null;
                }

             

             

            Thanks

            Hironmay Basu

            • 3. Re: ItemRenderer in Flex4
              zrowthterm

              In regards to error, you probably didn't define your states (normal, hovered, and selected) in your ItemRenderer.

              Try adding this to your ItemRenderer:

               

                                  <s:states>

                                      <s:State name="normal" />

                                      <s:State name="hovered" />

                                      <s:State name="selected" />

                                  </s:states>

               

               

              I had an error from the same line you pointed out in UIComponent.

              Hope this helps.