9 Replies Latest reply on Dec 4, 2011 6:59 PM by iFlashAppsToo

    My home button will not work after redoing project 3 times

    mediafred Level 1

      Using CS 5.5, I am using a single scene with buttons that all appear on the first frame along with code snippet based AS also on the first frame that when clicked, takes the user to a different frame. Everything seems to work fine, except, I have a button that when clicked on, is supposed to go back home to the first frame, though nothing happens when it is clicked on. Is there some conflicting code here?

       

      Thanks for any help!

       

      The following is my AS on the first frame:

       

      stop();

       

      Home_button.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame);

       

      function fl_ClickToGoToAndStopAtFrame(event:MouseEvent):void

      {

          gotoAndStop(1);

      }

       

       

      Browse.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_2);

       

      function fl_ClickToGoToAndStopAtFrame_2(event:MouseEvent):void

      {

          gotoAndStop(5);

      }

       

       

      Buy.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_3);

       

      function fl_ClickToGoToAndStopAtFrame_3(event:MouseEvent):void

      {

          gotoAndStop(10);

      }

       

       

      Gallery.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_4);

       

      function fl_ClickToGoToAndStopAtFrame_4(event:MouseEvent):void

      {

          gotoAndStop(15);

      }

       

       

      Help.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_5);

       

      function fl_ClickToGoToAndStopAtFrame_5(event:MouseEvent):void

      {

          gotoAndStop(20);

      }

        • 1. Re: My home button will not work after redoing project 3 times
          Ned Murphy Adobe Community Professional & MVP

          Put a trace in your Home button's event handler to see if/when it works.  My guess is that you have more than one instance of this button along the timeline and do not have an event listener assigned to each instance.

          1 person found this helpful
          • 2. Re: My home button will not work after redoing project 3 times
            mediafred Level 1

            Sorry I am very new to this.

             

            1. What do I do to put a trace in the home button's event handler?

             

            2. So if I have more than one instance of this on different frames, what do I need to do to my code to adjust it to make it work?

             

            Thank you.

            • 3. Re: My home button will not work after redoing project 3 times
              Ned Murphy Adobe Community Professional & MVP

              Place you code on its own layer and make sure it extends the length of your timeline so that it is accessible anywhere along it.

               

              For new instances of the buttons you should only need to add the event listener.

               

                 Home_button.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame);

               

              but you can also have this button on its own layer and have it extend the length of where it is used so that you only need one instance of it.

               

              The same event handler function can be shared as long as you have it on a layer that ius accessible for the length of the timeline.  To put a trace in the function, that's pretty much all you need to do...

               

                 function fl_ClickToGoToAndStopAtFrame(event:MouseEvent):void

                 {

                      trace("the button worked");

                     gotoAndStop(1);

                 }

               

              The trace() function is one of the key tools for troubleshooting code.  YOu can use it to see what the values of different properties/variables are at any time to help track down where something is going wrong (or even going right).  For the case just shown, all it is doing is letting you know if clicking the button actually resulted in the event handler function being executed.  If it does not trace the output indicated, you will know that the button is not connected to an event listener that is calling the function.

              1 person found this helpful
              • 4. Re: My home button will not work after redoing project 3 times
                mediafred Level 1

                I currently have all my AS in the same layer and frame.

                 

                1. How do you make sure the code extends the length of the timeline? I currently have the AS on a layer and the timeline extends around 50 frames. I do not have a keyframe at the end of the timeline. Should I be placing a keframe at the very end of my timeline OR does the code extend automatically? I thought it extended automatically.

                 

                Thanks!

                • 5. Re: My home button will not work after redoing project 3 times
                  Ned Murphy Adobe Community Professional & MVP

                  In the actions layer just right click the last frame and choose Insert Frame (not Insert Keyframe).  That will make your first frame of code extend uninterupted to the end frame.

                  • 6. Re: My home button will not work after redoing project 3 times
                    mediafred Level 1

                    Thanks for your help. I had not beein inserting a frame all the way to the end so far and things seemed to work for the most part. Is this just a bad idea? Do you always want to insert a frame at the end on the Actions layer?

                    • 7. Re: My home button will not work after redoing project 3 times
                      Ned Murphy Adobe Community Professional & MVP

                      Only if you need some code to be accessible there.  If something needs to access a function, then the function needs to be accessible in whatever frame it is in.  You can always just place a function in whatever frame it is called for, but that can make for some headaches when it comes to keeping track and finding things.

                       

                      What I will often do when working with code on a timeline is have two actions layers that extend as far as they need to be.  One is for functions and variables that might need to be available anywhere along the timeline - these are all in the very first frame where they are easy to find.  The other is for frame-specific commands, such as stop();, function calls, and anything else that is occuring at a specific frame.

                      1 person found this helpful
                      • 8. Re: My home button will not work after redoing project 3 times
                        iFlashAppsToo Level 3

                        does the home button work none of the time, or some of the time?

                        • 9. Re: My home button will not work after redoing project 3 times
                          iFlashAppsToo Level 3

                          check the name of the home button on the frame... is it "Home_button" or "Home"?

                           

                          check to make sure there aren't 2 home buttons on the frame.