12 Replies Latest reply on Jan 26, 2012 1:30 PM by cheftmo

    2 Problems with ItemRenderer

    cheftmo

      Hello, all:

       

      I am starting a new little project and am already running into 2 problems with an ItemRenderer. It's a cookware catalog; to see the problems, please browse to http://www.timos.com/LeCreuset/LeCreuset.html. I have enabled View Source.

       

      The renderer is renderers > ProductThumbnail.mxml.

       

      The tiles for products that are on sale show two prices, one of which is crossed out and this is

       

      PROBLEM 1:

      When you mouse over the tiles, the crossed-out price disappears. See the 6th. line up from the bottom of the mxml file, text="{cf.format(data.RETAILPRICE)}" lineThrough="true".

      Is this a bug with the lineThrough text attribute, or am I doing something wrong?

       

      PROBLEM 2:

      If you browse a couple of the categories, you will notice that in some of the tiles, both prices are the same - a stricken-out price is not supposed to appear unless it's higher - see private function showSalePrice() in the mxml file. Does anyone see something wrong with this function?

       

      I would appreciate any comments/ideas about this.

       

      Greetings,

       

      Carlos

        • 1. Re: 2 Problems with ItemRenderer
          Claudiu Ursica Level 4

          I would put my 2 cents on the fact that you are only changing state on creation complete. I see you are using a list which has visualization turned on e.g. your rendered get recycled. I would override the data setter in the renderer and update the state based on the data coming in and would be very surprised if that didn't fix it. 

           

           

          C

          • 2. Re: 2 Problems with ItemRenderer
            cheftimo Level 2

            OK Claudiu, thanks for replying.

             

            I tried turning virtualization (that is what you meant, right?) off.

            I also tried overriding the data setter to work from the Products AC, casting the data value as Product. Neither of these made any difference.

             

            I am confused about "update the state based on the data coming in": once the list is created, no data changes - the list is used only to click on the thumbnails to see info about each item; there are no data changes to the list. I have nothing in the code that tells the list to change states on mouseOver.

             

            Also, I can't figure out why both prices are displayed when they are equal. Just to make sure, I tried >= instead of just >

             

             

            private function showSalePrice():void{
                 if (product.RETAILPRICE >= product.PRICE){
                      currentState = "OnSale"}
            else{
                      currentState = "State1"
                 };
              }
            

             

            No difference. Can you see something wrong with this function?

             

            Can you think of something else?

             

            Regards,

             

            Carlos

            • 3. Re: 2 Problems with ItemRenderer
              Claudiu Ursica Level 4

              Hi

               

               

              "a list which has visualization turned" - that means it is already on unless you turn it off, which is not your case.

               

               

              inside list class

               

                  public function List()

                  {

                      super();

               

                      useVirtualLayout = true;

              ....

               

               

              inside list base

               

              public function set useVirtualLayout(value:Boolean):void

                  {

                      if (value == useVirtualLayout)

                          return;

                         

                      _useVirtualLayout = value;

                      if (layout)

                          layout.useVirtualLayout = value;

                  }

                 

               

               

               

              Since is on it means your renderers will get recycled. e.g reused:

               

               

              renderer 1 is used to display firs item. you scroll renderer 1 is used to display 50th item (or whatever number).

               

              when this is happening  the data setter gets executed. That means your data upon which you based your state is no longer valid.

               

              You only invoke showSalePrice() on creation complete. That means it will only execute once when the renderer is created.

               

              When I said to override the data setter it wasn't for you to cast the data or whatever, ...  it was to update the state based on the new data. e.g to call showSalePrice which in turn will give you the correct state.

               

               

              override public function set data(value:Object):void

              {

                  super.data = value;

               

                     //new data comming in --- need to upate state based on new data

                 

               

                  showSalePrice();

              }

               

              C

              • 4. Re: 2 Problems with ItemRenderer
                cheftimo Level 2

                Hi Claudiu et al:

                 

                I did try turning off VirtualLayout in the s;List. One can do that in MXML by setting useVirtualLayout="false". That made no difference.

                 

                Unless I am missing something, this issue of the state changing onMouseOver is another bug. I say that because I tried using an mx:TileList and the problem disappeared.

                 

                That still leaves the problem with the prices. Here's the function again:

                 

                 

                private function showSalePrice():void{
                     if (data.RETAILPRICE > data.PRICE){
                          currentState = "OnSale"}
                     else{
                          currentState = "State1"};
                     }
                

                 

                So, can anybody see something wrong with this function?

                 

                Carlos

                • 5. Re: 2 Problems with ItemRenderer
                  Claudiu Ursica Level 4

                  Did you put a call of your funtion inside the overriden data setter? Like below?

                   

                   

                  override public function set data(value:Object):void

                  {

                      super.data = value;

                   

                         //new data comming in --- need to upate state based on new data

                   

                   

                   

                   //call show sale price to update the current state ....

                   

                      showSalePrice();

                  }

                   

                  the fact that renderers are recycled is fine. You are not updating your renderer state when their are recycled . In your rendrerer place the above code snippet e.g ProductThumbnail.mxml place the above code inside the script blocks.

                   

                   

                  C

                  1 person found this helpful
                  • 6. Re: 2 Problems with ItemRenderer
                    cheftimo Level 2

                    Claudiu, your suggested override of the function fixed the issue of the prices. Thank you for that.

                     

                    I still need to figure out why a onMouseOver on a tile changes its "OnSale" currentState to "State1". This does not happen when I use the mx:TileList. I do not have anything in the code for anything happening on an onMouseOver event.

                     

                    Any ideas, anybody? (The project is here: http://www.timos.com/LeCreuset/LeCreuset.html).

                     

                    Salud,

                     

                    Carlos

                    • 7. Re: 2 Problems with ItemRenderer
                      Claudiu Ursica Level 4

                      I strongly suspect it has to do with using s:ItemRenderer and the fact that it has states baked inside. Try to use a DataRenderer instead, or override the getCurrentRendererState() inside your current renderer and make it return only the 2 states that you are using.

                      • 8. Re: 2 Problems with ItemRenderer
                        cheftimo Level 2

                        Claudiu wrote:

                         

                         

                        Did you put a call of your funtion inside the overriden data setter? Like below?

                         

                         

                        override public function set data(value:Object):void

                        {

                            super.data = value;

                         

                               //new data comming in --- need to upate state based on new data

                         

                         

                         

                        //call show sale price to update the current state ....

                         

                            showSalePrice();

                        }

                         

                        the fact that renderers are recycled is fine. You are not updating your renderer state when their are recycled . In your rendrerer place the above code snippet e.g ProductThumbnail.mxml place the above code inside the script blocks.

                         

                         

                        C

                         

                         

                        I wanted to mark the above as a Helpful Answer but haven't been able to figure out how. Anybody know?

                        • 9. Re: 2 Problems with ItemRenderer
                          cheftimo Level 2

                          "Try to use a DataRenderer instead, or override the getCurrentRendererState() inside your current renderer"

                           

                          I tried using DataRenderer, problem still the same.

                           

                          I looked in the source AS files and the generated ActionScript files, but could not find function called getCurrentRendererState() anywhere.

                           

                          As a temporary hack, I added

                          mouseOver="showSalePrice()

                          to the ItemRenderer (ProductThumbnail.mxml).

                           

                          That did not solve the issue either. If anyone can think of other things to try, I am all ears.

                           

                          Regards,

                           

                          Carlos

                          • 10. Re: 2 Problems with ItemRenderer
                            DonMitchinson Level 2

                            cheftimo wrote:

                            I wanted to mark the above as a Helpful Answer but haven't been able to figure out how. Anybody know?

                             

                            Find the reply - bottom left corner will be button "Helpful Answer"

                            You must be logged in to see it.

                            • 11. Re: 2 Problems with ItemRenderer
                              cheftmo Level 1

                              Strange: my browser was keeping me logged in. I was able to post replies on different visits without logging in, but the Helpful/Correct Answer buttons were not to be found.

                               

                              I logged out and logged back in and the buttons showed up.

                               

                              I guess Flash Builder is not the only Adobe program with bugs.

                               

                              Thanks anyway, Don.

                               

                              Carlos

                              • 12. Re: 2 Problems with ItemRenderer
                                cheftmo Level 1

                                Claudiu:

                                 

                                " I strongly suspect it has to do with using s:ItemRenderer and the fact that it has states baked inside. Try to use a DataRenderer instead, or override the getCurrentRendererState() inside your current renderer and make it return only the 2 states that you are using."

                                 

                                When I tried DataRenderer before, I think I forgot to override the set data() function. I tried again after doing that and everything is working fine now.

                                 

                                Thank you very much.

                                 

                                Carlos