16 Replies Latest reply on Jul 14, 2011 10:17 AM by Shongrunden

    s:ItemRenderer click event is not reliable; any workarounds?

    TheOriginalEdge Level 1

      I got feedback from user testing, and confirmed it for myself.  Sometimes a click is "ignored".  This seems to happen if the mouse is moved rapidly away from the label just as it is being clicked.

       

      This is under MXML which defines a spark List, with MXML for a spark ItemRenderer, with three Labels each given a String from the data object.  Each of these Labels defines a click event listener, they each link to the same function in the ItemRenderer.  Putting a trace in that listener confirmed that some clicks are simply ignored.

       

      Has anyone else experienced this and found a work around?  I'm hoping that there might be a more reliable event to listen to, for instance.  Source code of the item renderer is included below for completeness.

       

      This is using Flash Builder 4.5, with the most recent libraries.

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                      xmlns:s="library://ns.adobe.com/flex/spark"
                      xmlns:mx="library://ns.adobe.com/flex/mx"
                      autoDrawBackground="true"
                      >
         
          <fx:Script>
              <![CDATA[
             
                  [Embed(source="../src/images/cancel_12.png")]
                  [Bindable]    public var icon:Class;
                 
                  override public function set data(value:Object):void {     
                      if(value != null)  {
                          super.data = value;
                          deleteIcon.source=new icon();
                      }  
                  }

       

                  protected function item_Handler(event:MouseEvent):void
                  {
                      trace("got click event", data.name);                   
                  }
                 
                  protected function deleteIcon_clickHandler(event:MouseEvent):void
                  {
                      trace("got delete event", data.name);
                  }
                 
              ]]>
          </fx:Script>
         
          <s:HGroup height="100%" verticalAlign="middle"
                    paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5">
              <s:HGroup>
                  <s:Label text="{data.name}" width="120" click="item_Handler(event)" />
                  <s:Label text="{data.price}" width="15" click="item_Handler(event)" />
                  <s:Label text="{data.date}" width="75" click="item_Handler(event)" />
                  <s:Image id="deleteIcon" click="deleteIcon_clickHandler(event)" />
              </s:HGroup>
          </s:HGroup>
         
      </s:ItemRenderer>