We help IT Professionals succeed at work.

flex mouse event

yarekGmail asked
Last Modified: 2013-11-11
hello experts,

Here is a very simple Flex code.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
		import mx.controls.Alert;
		private function init():void {
			red.addEventListener(MouseEvent.CLICK , clicked);
			green.addEventListener(MouseEvent.CLICK , clicked);
			blue.addEventListener(MouseEvent.CLICK , clicked);
		private function clicked(e:MouseEvent):void {
			Alert.show(e.currentTarget.name+" clicked");
		<mx:Canvas x="31" y="46" width="200" height="200" backgroundColor="#FF0000" id="red"  />
		<mx:Canvas x="31" y="46" width="200" height="200" backgroundColor="#00FF00"  id="green" />
		<mx:Canvas x="31" y="46" width="200" height="200" backgroundColor="#0000FF"  id="blue" />

Open in new window

What I try to achieve is to make red or green clickable.
It is important not to change the layout (no nesting canvas).
I can do it if I make blue visible = false, but I need to keep all layers visible !
It doesn't work if you remove the listener from blue neither.

So how to make the others layers answer the events ?

Watch Question

The 3 canvas's are covering each other. So your only getting the click event to the top one

if you change the following lines like below

      <mx:Canvas x="11" y="46" width="200" height="200" backgroundColor="#FF0000" id="red"  />
      <mx:Canvas x="21" y="46" width="200" height="200" backgroundColor="#00FF00"  id="green" />
      <mx:Canvas x="31" y="46" width="200" height="200" backgroundColor="#0000FF"  id="blue" />

You can see them all and will be able to click them all.


yes thanks I know that !
but "It is important not to change the layout (no nesting canvas)."

Well what are you trying to achieve. Why would you want someone to click something that they cant see.


To simulate  a layer system like Photoshop.

Forget it I solved it by myself. Try to answer to the quetsion if you kno wthe answer next time.
This one is on us!
(Get your first solution completely free - no credit card required)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.