6 Replies Latest reply on Feb 19, 2011 6:36 AM by Yozef0

    ♺ List item renderer confuses states

    Yozef0 Level 1

      I have a List component that handles an ArrayCollection of around 1000 objects.

       

      The Flex List component handles that great, especially with recycling the items in view.

       

      Each object has a property called: date_purchased ; If this property has a value (as in not null) then the state of the item in the List gets set to a sold state. If the property is null then the state of the item is set to normal.

       

      What the code below does, is that when the list first renders --> all items that have a date_purshased value, then it correctly sets the item to the sold state.

      Though, all items, that don't have a value for the date_purshased, the state gets set to normal with mouseEnabled, just like the code says.

       

      The Problem: When the ticket is in the normal state, the hover state activates when hovered, but when clicked... I expected the item renderer to alse set itself to selected, though, that is not the case; so I added the Click event listener below.

      Hint: I've uncommented the CLICK event listener, and placed a breakpoint in the select() function. I see the state being changed to selected, though it does not do it n the player...?

       

      ItemRenderer:

       

       

      override public function set data(value:Object):void {
           ti_ti.text = value.slots_id;
           if (value.date_purchased != null) {
           currentState = 'sold';
           mouseChildren = false;
           mouseEnabled = false;
           } else {
           currentState = 'normal';
           mouseChildren = true;
           mouseEnabled = true;
           //addEventListener(MouseEvent.CLICK, select);
           }
      }
      private function select(e:MouseEvent):void {
           if (currentState != 'selected') {
                currentState = 'selected';
           } else currentState = 'hovered';
      }
      and the states:
      <s:states>
           <s:State name="normal"/>
           <s:State name="hovered"/>
           <s:State name="selected" />
           <s:State name="sold"/>
      </s:states>
      
      

       

        • 1. Re: ♺ List item renderer confuses states
          Flex harUI Adobe Employee

          There was another thread like this recently.  I think you don't want to set

          the currentState in the data setter.  Look for a recent post by me that

          mentions getCurrentRendererState.

          1 person found this helpful
          • 2. Re: ♺ List item renderer confuses states
            Yozef0 Level 1

            Hi Alex,

             

            I've searched a lot for that post (on this forum and on google). Not sure if this is the post you were talking about: http://tech.groups.yahoo.com/group/flexcoders/message/161146

             

            I have fixed the setter of the data not to also manage the state (I figured it was inappropriate there)... overrode the getCurrentRendererState, I'm managing the state staight from the data. When I run the following... All sold items show as sold... and normal states show as normal. When I try to hover over the normal state, it dosen't play the hovered state, and when I click to the selected state. These built in states don't work.

             

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

                 super.data = value;

                 ticketNumber_ti.text = value.slots_id;

            }

             

             

            override protected function getCurrentRendererState():String {

                 var state:String;

                 if (data.date_purchased != null) {

                      state = 'sold';

                      mouseChildren = false;

                      mouseEnabled = false;

                 }  else {

                      state = 'normal';

                      mouseChildren = true;

                      mouseEnabled = true;

                 }

                 return state;

            }

             

             

            On another note, the states only update, once I start scrolling, everything updates... I tried to validateDisplayList() to the List after setting the dataProvider with no luck.

            Once I find a solution I will certainly add it to my Blog as I have not found a lot of solutions for this problem.

             

            Any help is grteatly appreciated.

            • 3. Re: ♺ List item renderer confuses states
              Flex harUI Adobe Employee

              It looks like you want to replace the normal state with the sold state under

              certain conditions.  You are not calling the super class so therefore it

              will never return the hovered or selected state.  I would try something more

              like this:

               

              override protected function getCurrentRendererState():String {

                   var state:String = super.getCurrentRendererState();

                   if (state == "normal")

                   {

                       if (data.date_purchased != null) {

                            state = 'sold';

                            mouseChildren = false;

                            mouseEnabled = false;

                       } else {

                        state = 'normal';

                        mouseChildren = true;

                        mouseEnabled = true;

                       }

                   }

                   return state;

              }

              • 4. Re: ♺ List item renderer confuses states
                Yozef0 Level 1

                Thank you very much for your response Alex,

                 

                I have added the code you gave me, and it makes sense, though the list now only shows the normal state... without the mouse event?!

                 

                Even though the data.date_purshased is not null (supposedly a sold state) in the cases of the video below, the actualy item in the Flash player is the normal state... with the MouseChildren & MouseEnabled to false (can't click).

                 

                I have added a breakpoint, and created a video of what I am seeing, with the debugger it looks alright, though it's not being rendered the appropriate state in the player.

                • 5. Re: ♺ List item renderer confuses states
                  Flex harUI Adobe Employee

                  I'm not sure why you are manipulating mouseEnabled/mouseChildren.  Maybe

                  take out that code and see if it behaves better.  Or debug into it, or add

                  trace statements so you can figure out why it never returns the "sold"

                  state.

                  • 6. Re: ♺ List item renderer confuses states
                    Yozef0 Level 1

                    Oh My God!!

                     

                    Thank you so much Alex