Check coordinate for mouse click
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="white">
<mx:Script>
import mx.controls.Alert;
private function handleMouseDown(event:MouseEvent):void {
var pt:Point = new Point(event.localX, event.localY);
pt = event.target.localToGlobal(pt);
pt = c1.globalToContent(pt);
var whichColor:String = "aaa";
if (pt.x < 150) {
if (pt.y < 150)
whichColor = "red";
else
whichColor = "blue";
}
Alert.show("You clicked on the " + whichColor);
}
</mx:Script>
<mx:Canvas id="c1" borderStyle="none" width="300" height="300" mouseDown="handleMouseDown(event);">
<mx:Canvas width="150" height="150" x="0" y="0" backgroundColor="red">
<mx:Button label="Red" />
</mx:Canvas>
<mx:Canvas width="150" height="150" x="0" y="150" backgroundColor="blue">
<mx:Button label="Blue" />
</mx:Canvas>
</mx:Canvas>
</mx:Application>
Related examples in the same category