Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3596860
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:02:37+00:00 2026-05-18T20:02:37+00:00

This is probably really simple but i cant figure it out. Take a look

  • 0

This is probably really simple but i cant figure it out. Take a look at the code, i moved 2 instances of this button class (CategoryButton) onto the stage. As you can see when you click a button it should gotoAndPlay(3), record itself as the selectedBtn. When the second button is clicked, it should re-enable the listener for the first button, remove listeners for itself and set itsself as the newly selected button. Unfortunately this code is not doing that. When i click on the first button it moves the button to frame 3, and removes its listeners. I click the second button and it does the same thing, except it does not add listeners for the first button again.

Im new to AS3, any help is greatly appreciated, thank you.

package classes {
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    import flash.display.Sprite;

    public class CategoryButton extends MovieClip{

        //this stores the currently selected button
        public var selectedBtn:Object;

        public function CategoryButton() {
            // listen for over
            addEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);

        }

        protected function rolloverToggle(event:MouseEvent):void {
            gotoAndStop(2);
            removeEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
            addEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
            addEventListener(MouseEvent.CLICK, buttonToggle);
        }

        protected function rolloutToggle(event:MouseEvent):void {
            gotoAndStop(1);
            removeEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
            addEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
        }

        protected function buttonToggle(event:MouseEvent):void {
            if(selectedBtn) {
                trace(selectedBtn.name)
                selectedBtn.addEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
                selectedBtn.gotoAndStop(1);

                event.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
                event.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
                event.currentTarget.removeEventListener(MouseEvent.CLICK, buttonToggle);

                event.currentTarget.gotoAndStop(3);

                selectedBtn = event.currentTarget;
            }else {

                selectedBtn = event.currentTarget;
                trace(selectedBtn.name);
                selectedBtn.removeEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
                selectedBtn.removeEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
                selectedBtn.removeEventListener(MouseEvent.CLICK, buttonToggle);

                selectedBtn.gotoAndStop(3);
            }
        }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:02:38+00:00Added an answer on May 18, 2026 at 8:02 pm

    How i fixed it:

    1. Button A is clicked (A is set as selectedBtn, listeners disabled, state changed to frame 3)
    2. Button B is clicked (selectedBtn’s listener is reset, state changed, selectedBtn is set to Button B)

    This is where the problem was, A’s listener was set as follows:

    addEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
    

    This was causing Button B to come alive again. The fix was to simply change the listener to the currentTarget and also the gotoAndStop, for the over and out states.

    event.currentTarget.gotoAndStop(1);
    event.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
    
    
    package classes {
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    
    public class CategoryButton extends MovieClip{
    
        //this stores the currently selected button
        public static var selectedBtn:Object;
    
        public function CategoryButton() {
            // listen for over
            addEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
            trace("called");
    
        }
    
        protected function rolloverToggle(event:MouseEvent):void {
            event.currentTarget.gotoAndStop(2);
            event.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
            event.currentTarget.addEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
            event.currentTarget.addEventListener(MouseEvent.CLICK, buttonToggle);
        }
    
        protected function rolloutToggle(event:MouseEvent):void {
            event.currentTarget.gotoAndStop(1);
            event.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
            event.currentTarget.addEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
        }
    
        protected function buttonToggle(event:MouseEvent):void {
            if(selectedBtn) {
                trace(selectedBtn.name);
                selectedBtn.addEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
                selectedBtn.gotoAndStop(1);
    
                event.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
                event.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
                event.currentTarget.removeEventListener(MouseEvent.CLICK, buttonToggle);
    
                event.currentTarget.gotoAndStop(3);
    
                selectedBtn = event.currentTarget;
            }else {
    
                selectedBtn = event.currentTarget;
                selectedBtn.removeEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
                selectedBtn.removeEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
                selectedBtn.removeEventListener(MouseEvent.CLICK, buttonToggle);
    
                selectedBtn.gotoAndStop(3);
    
            }
        }
    
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably really simple but i cant figure it out. Take a look
This is probably a really simple problem, but I can't figure out how to
Ok, this is probably really simple, but I just can't figure it out. I
I know this is probably really obvious, but I cannot figure out why I
So this is probably really simple but for some reason I can't figure it
This is probably a really simple question but... I would like to do a
This is probably a really simple jQuery question, but I couldn't answer it after
Ok, this probably has a really simple answer, but I've never tried to do
Probably a really simple one this - I'm starting out with C# and need
This is probably a really simple question but I can't seem to find anything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.