Question { 6903 }
Write a function that responds to a click anywhere on the
page by displaying an alert dialog. Display the event name
if the user held Shift during the mouse click. Display the
element name that triggered the event if the user held Ctrl
during the mouse click.
Answer
//1)
stage.addEventListener(MouseEvent.CLICK, clickHandler)
function clickHandler(e:MouseEvent){
trace("Mouse Clicked")
}
//2)
stage.addEventListener(MouseEvent.CLICK, shiftHandler);
function shiftHandler(e:MouseEvent) {
if (e.shiftKey) {
trace("Mouse Clicked with Shift key");
}
}
//3)MouseEvent
stage.addEventListener(MouseEvent.CLICK, controlHandler);
function controlHandler(e:MouseEvent) {
if (e.ctrlKey) {
trace("Mouse Clicked with Ctrl key");
}
}