Aug 1, 2010 12:15 PM
Expected Behaviour? [VIDEO]
-
Like (0)
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
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
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>
Ahaaaah!!! Excellent thankyou for that! Again, Flex delivers with a hidden property ![]()
North America
Europe, Middle East and Africa
Asia Pacific
Copyright © 2011 Adobe Systems Incorporated. All rights reserved.
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).