Flex child components that don't interfere with mouse events

Gary McGhee - Tuesday, May 19, 2009

I have a bitmap that I want to act as a button, complete with the standard mouse hover cursor (hand).  I also have a label I want overlaid over the bitmap. 

Firstly, there are various posts out there about custom mouse cursors, but it surprisingly hard to find anything on the standard hand pointer that appears when the mouse is over a link. "buttonMode = true" is the answer to that one, but it doesn't work for everything.

Secondly, the label must be in front of the bitmap, but not interefere with the mouse. The answer to this was to make the label a child of the image, and then to set "imgCart.mouseChildren = false". This makes the label ignore mouse events, which fall through to its parent.

Some actionscript in creationComplete that makes the label a child of the image control, then centers its position within the image :

var lbl: Label = lblCartCount;
lbl.parent.removeChild(lbl)
imgCart.addChild(lbl);
lbl.x = (imgCart.width - lbl.width) / 2 - 5
lbl.y = (imgCart.height - lbl.height) / 2