3 Replies Latest reply on Aug 1, 2010 11:58 PM by cannyshammy

    Expected Behaviour? [VIDEO]

    cannyshammy

      Hi Guys,

       

      I have just come accros an issue with a rect inside of a group. Im trying to listen for mouse overs when rolling over the rect only but im getting rollover events even when rolling over white space.

       

      Can anyone confirm if this is the correct behaviour for GraphicElements within groups?

       

       

      Code is:

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

         xmlns:s="library://ns.adobe.com/flex/spark"

         xmlns:mx="library://ns.adobe.com/flex/mx">

       

       

      <s:Group rollOver="trace('ya')">

      <s:Rect x="100" y="100" width="20" height="20">

      <s:fill>

      <s:SolidColor color="0x00ff00" />

      </s:fill>

      </s:Rect>

      </s:Group>

       

       

      </s:WindowedApplication>

       

      Cheers,

      Mike

        • 1. Re: Expected Behaviour? [VIDEO]
          cannyshammy Level 1

          Actually I think I already know the answer to this one but ill leave it up anyways.

           

          Its because group is a DisplayObject and when a child is added the rollover will just do a Rectangle.containsPoint(mouseX, mouseY) and hence return true.

           

          So in other words if you have a group at 0,0 and a child element at 100,100 with width 10 and height 10 the group is going to have a hitbox area == 0,0,110,110 even though only a small part of it would return true in an alpha hittest.

           

          Cheers,

          Mike

          • 2. Re: Expected Behaviour? [VIDEO]
            Shongrunden Adobe Employee

            Group.mouseEnabledWhereTransparent might be helpful to you:

             

                <s:Group mouseEnabledWhereTransparent="false" rollOver="trace('ya')">
                    <s:Rect x="100" y="100" width="20" height="20">
                        <s:fill>
                            <s:SolidColor color="0x00ff00" />
                        </s:fill>
                    </s:Rect>
                </s:Group>
            • 3. Re: Expected Behaviour? [VIDEO]
              cannyshammy Level 1

              Ahaaaah!!! Excellent thankyou for that! Again, Flex delivers with a hidden property