Skip navigation
Dinipants
Currently Being Moderated

Button Stays in "Over" state

Apr 19, 2012 8:23 PM

Tags: #help #adobe #flash #new #cs #button #3 #actionscript #5.5 #in #beginner #between #over #stuck #screens #stays

Hey guys.

 

So I am brand new to programming. I was using a book to follow along an example of basic programming in which you create an interactive storybook. It consists of three separate screens with buttons to toggle between them. I made the buttons greyish, then rainbow when your mouse is over them and them made them stay rainbow and move down and to the right a bit when you click them.

 

That all works fine, but I notice when I go to one screen, then go back to the other, the button is displayed in it's over state (as if the mouse is over it, which it isn't). In this case, the button is rainbow. If I put my mouse over it then take it off again, it resets it and it changes to the grey up state again. I was wondering what might cause this? The code I use it quite simple, I'm wondering if it's a script thing, or something to do with my button symbols.

 

I've incldued the code below. Please ignore all the extra comments I added, I put them in to help me learn

 

Thanks for any help!

 

package // groups all your code neatly together

{

    import flash.display.MovieClip; //MovieClip is a pre-made collection of classes which allow you to display things on screen. It must be imported BEFORE your class definition

    import flash.events.MouseEvent; //MouseEvent is another pre-made class used for mouse actions

   

    //Classes are building blocks, blueprints for creating instances of themselves

    public class Main extends MovieClip //extending MovieClip allows this class to use all the properties and methods of MovieClip to hlep it display things on the screen

                                                         //importing and extending classes is called "INHERITANCE"

    {

        //These are variable declarations. It has (name of the variable[can be anything]):(type of variable being created)

        //Variables just represent changing information, such as score or current location

        var startPage:StartPage; //creates a variable called startPage, to store instances of StartPage (the library symbol)

        var leftHill:LeftHill;

        var rightPond:RightPond;

       

        public function Main() //this runs all the code within it once the class it's in is instantiated (it's the constructor method)

                                       //public means that this constructor method is freely available to be used by different classes from different packages

                                       //the parantheses contain parameters for this function (this function doesn't need any, so they are empty)

        {

            //These are directives, a single line action that the function performs

            startPage = new StartPage; //this changes the variable startPage to an instance of the StartPage symbol

            leftHill = new LeftHill;

            rightPond = new RightPond;

 

            //addChild is a built in method that (amongst other things) displays instances of MovieClip symbols on the stage

            addChild(startPage); //adds its argument (what's in the brackets) to the "display list", instances in the display list are visible on the stage

                                 //in this case the argument is the variable startPage, which was defined as an instance of  our StartPage library symbol

       

            //Event Listeners, these are built in methods that listen for a particular event, in this case clicking on a butotn

            //With dot notation, things live inside whatever is to their left of the dot

            startPage.hillButton.addEventListener(MouseEvent.CLICK, onHillButtonClick);

            startPage.pondButton.addEventListener(MouseEvent.CLICK, onPondButtonClick);

            leftHill.backToStartButton.addEventListener(MouseEvent.CLICK, onBackButtonClick_Hill);

            rightPond.backToStartButton.addEventListener(MouseEvent.CLICK, onBackButtonClick_Pond);

           

            //Event Handlers, these 'handle' the event, doing whatever they are programmed to do when the corresponding event is heard

            //This 'function' line is a function definition. Fucntion definitions are block statements that include one or more directives

            //The name of the function (here 'onHillButtonClick') is known as the method name

            //You can call upon the function you have defined using a 'method call' and it will perform ALL the directives within it

            //At the end is the 'type declaration', which indicates what kind of information might be returned to the program from the function. Here nothing is returned, so it's "void"

            function onHillButtonClick(event:MouseEvent):void

            {

                addChild(leftHill);

                removeChild(startPage); //removeChild removes an instance from the stage. However, it is still stored in the Flash Player memory

            }

            function onPondButtonClick(event:MouseEvent):void

            {

                addChild(rightPond);

                removeChild(startPage);

            }

            function onBackButtonClick_Hill(event:MouseEvent):void

            {

                addChild(startPage);

                removeChild(leftHill);

            }

            function onBackButtonClick_Pond(event:MouseEvent):void

            {

                addChild(startPage);

                removeChild(rightPond);

            }

        }

    }

}

 
Replies
  • Currently Being Moderated
    Apr 20, 2012 4:56 AM   in reply to Dinipants

    The problem is likely due to having a button symbol getting cut off from access before it can have a mouseout event register.  If you use movieclips as buttons instead and assign them ROLL_OVER and ROLL_OUT listeners for changing their frames between gray and rainbow, the problem might go away.

     

     

    PS - It is very difficult to read your code with all of the comments - you'll increase you chances of getting help if you present only what is relevant (just the code in this case)

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points