We help IT Professionals succeed at work.

flex mouse event

yarekGmail
yarekGmail asked
on
386 Views
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()">
<mx:Script>
	<![CDATA[
		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:Script>
		<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" />
	
</mx:Application>

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 ?

regards
Comment
Watch Question

Commented:
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.

Author

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

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

Author

Commented:
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.
Thanks
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
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.

OR

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.