1 Reply Latest reply on Feb 15, 2013 4:41 AM by archemedia

    IconItemRenderer interactivity

    archemedia Level 4

      Hi,

      I'm using an iconItemRenderer in a mobile list. I have an icon and a decorator. So, a user can click the list item, the icon or the decorator. Does anyone know how to distinguish these three events? I can only listen to the click event but that goes for the whole itemRenderer.

      I tried this:

      iconDisplay.addEventListener( MouseEvent.CLICK, icon_clickHandler ); 

      but no luck.

      Any help will be appreciated

      Thanks,

       

      Dany

        • 1. Re: IconItemRenderer interactivity
          archemedia Level 4

          In the mean time, I found out that both iconDisplay and decoratorDisplay are BitmapImages which can't have event listeners.

          I created this workaround.

          If someone has a better solution, please let me know!

           

          private function clickHandler( event:MouseEvent ):void

                                        {

                                                  var cp:Point = new Point( event.localX, event.localY );

                                                  if ( isIconClicked( cp ) )

                                                  {

                                                            icon_clickHandler();

                                                  } else if ( isDecoratorClicked( cp ) )

                                                  {

                                                            decorator_clickHandler();

                                                  } else

                                                  {

            trace("label clicked");

                                                  }

                                        }

           

                                        private function label_clickHandler(event:MouseEvent):void

                                        {

            trace("label clicked");

                                                  event.stopImmediatePropagation();

                                        }

           

                                        private function icon_clickHandler():void

                                        {

            trace("icon clicked");

                                        }

           

                                        private function decorator_clickHandler():void

                                        {

            trace("decorator clicked");

                                        }

           

                                        private function isIconClicked( point:Point ):Boolean

                                        {

                                                  if (!iconDisplay)

            return false;

           

                                                  var ix:Number = iconDisplay.x;

                                                  var iy:Number = iconDisplay.y;

                                                  var iw:Number = iconDisplay.width;

                                                  var ih:Number = iconDisplay.height;

           

                                                  return ( point.x > ix && point.x < ix + iw && point.y > iy && point.y < iy + ih )

                                        }

           

                                        private function isDecoratorClicked( point:Point ):Boolean

                                        {

                                                  if (!decoratorDisplay)

            return false;

           

                                                  var ix:Number = decoratorDisplay.x;

                                                  var iy:Number = decoratorDisplay.y;

                                                  var iw:Number = decoratorDisplay.width;

                                                  var ih:Number = decoratorDisplay.height;

           

                                                  return ( point.x > ix && point.x < ix + iw && point.y > iy && point.y < iy + ih )

                                        }