Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Event listeners and user feedback

Community Beginner ,
Jan 20, 2011 Jan 20, 2011

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.

TOPICS
ActionScript
476
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 20, 2011 Jan 20, 2011

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.

Translate
LEGEND ,
Jan 20, 2011 Jan 20, 2011

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");
    }
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 20, 2011 Jan 20, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 20, 2011 Jan 20, 2011
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines