I recently ran across an interesting way to handle mouse events in a friend’s bit of code. I wanted to share it here. I feel like it hurts readability and is not always the preferred way to go about handling mouse events, but it certainly makes for some concise code. Quite good for when speed is of the essence.
1 2 3 4 5 6 7 8 9 10 11 12 13 | button1.addEventListener(MouseEvent.CLICK, onClick) button2.addEventListener(MouseEvent.CLICK, onClick) function onClick(e:MouseEvent):void { switch(e.target.name){ case "button1": //do something break; case "button2": //do something else break; } } |