Copy link to clipboard
Copied
I have an event listener running a function from a button that updates the display and gives the user positive feedback. Works great.
Cannot figure out how to get the hint feedback movie clip to run if the user clicks anywhere OTHER than the button. Do I have to declare the button as a variable somehow? That didn't make sense to me but don't variables need to be defined in order to create conditional rules? I just want the function to do A if the button is clicked and B if the user clicks anywhere else. I tried attaching the event listener to the stage but could not isolate the button away so it ran the hint movie even if you clicked the button.
You're welcome. Actually, that second trace would be more correct to indicate that the button was not clicked... some other object than the stage may have been clicked.
Copy link to clipboard
Copied
Something like the following should work, if the button's instance name is "btn"...
stage.addEventListener(MouseEvent.CLICK, processClick);
btn.mouseChildren = false;
function processClick(evt:MouseEvent):void {
if(evt.target == btn){
trace("btn clicked");
} else {
trace("stage clicked");
}
}
Copy link to clipboard
Copied
thank you so very much—helps me understand the logic too.
(keep trying to change it to question answered but it doesn't seem to work) My question has been answered.
Copy link to clipboard
Copied
You're welcome. Actually, that second trace would be more correct to indicate that the button was not clicked... some other object than the stage may have been clicked.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now