7 Replies Latest reply on Jan 23, 2011 8:17 AM by Ned Murphy

    Hiding the "Next" Button AS3

    thefab4

      Hi Apologies if this has been discussed before.

       

      I have a small microsite built using Flash 4. It contains 5 'pages' assigned to individual keyframes, each keyframe separated by 5 frames (F5s). Each Keyframe is labelled 'page1' through to 'page5'. I have a navigation bar for the entire site which includes NEXT and PREVIOUS buttons. When the user reaches the LAST PAGE/KEYFRAME I do not want the NEXT BUTTON to show. I suspect it is something simple like nextbutton.visible = true - but I've spent a day trying to work out how to do this but without success.

       

      I am using AS3 and the existing coding is shown below. Any help much much appreciated.

       

      Thanks George

       

      nextbutton.addEventListener(MouseEvent.CLICK, nextPage);
      previousbutton.addEventListener(MouseEvent.CLICK, prevPage);

       

      function nextPage(event:MouseEvent):void {
        
          var thisLabel:String = MovieClip(root).currentLabel;
          var thisLabelNum:String = thisLabel.replace("page", "");
          var curNumber:Number = Number(thisLabelNum);
          if (curNumber < 5) {
            
              var nextNum:Number = curNumber + 1;
              MovieClip(root).gotoAndStop("page" + nextNum);
            
          }
      }
      function prevPage(event:MouseEvent):void {
        
          var thisLabel:String = MovieClip(root).currentLabel;
          var thisLabelNum:String = thisLabel.replace("page", "");
          var curNumber:Number = Number(thisLabelNum);
          var prevNum:Number = curNumber - 1;
          MovieClip(root).gotoAndStop("page" + prevNum);

       

      }

        • 1. Re: Hiding the "Next" Button AS3
          Ned Murphy Adobe Community Professional & MVP

          I would just not have the next button present in the last section.  Or you could use...  nextbutton.visible = false in that last section's frame, though them you would have to turn it visible again if you stepped back.

          • 2. Re: Hiding the "Next" Button AS3
            thefab4 Level 1

            Hi Ned

             

            Thanks for that.

             

            Unfortunately that won't work because the navbar is on its own layer and is set up to show through all the keyframes. This means I can't remove the NEXT BUTTON without removing from every keyframe.

             

            I have found a bit of AS that partially works. If I add:

            else if (curNumber == 5){

            nextbutton.visible = false;
            }

             

            after the (curNumber < 5) statement is closed, then it seems to work. BUT the NEXT BUTTON stays hidden when I press the PREVIOUS BUTTON.

             

            Any suggestions??

             

            Thanks

             

            George

            • 3. Re: Hiding the "Next" Button AS3
              Ned Murphy Adobe Community Professional & MVP

              That was my other suggestion, which I indicated you would need to make it visible again if you step back.  Think it thru and you can solve this without further help.  Any click of the prev button is stepping back, so....

              • 4. Re: Hiding the "Next" Button AS3
                thefab4 Level 1

                Hi Ned

                 

                I re-read your suggestion AFTER I had posted my reply and I'm delighted to say it now works.

                 

                Unfortunately, I have another related problem that you may be able to help with.

                 

                On the Home Page (i.e. KEYFRAME 1) there are a series of button links that take me to the other keyframe/pages. I also need the NEXT BUTTON icon to hide when that keyframe is accessed from KEYFRAME 1 - here is the code:

                 

                stop();
                leftbutton1.addEventListener(MouseEvent.MOUSE_DOWN, leftbutton1pressed);

                 

                function leftbutton1pressed(event:MouseEvent){
                    gotoAndStop("page2");
                }

                 

                leftbutton2.addEventListener(MouseEvent.MOUSE_DOWN, leftbutton2pressed);

                 

                function leftbutton2pressed(event:MouseEvent){
                    gotoAndStop("page3");
                }

                 

                leftbutton3.addEventListener(MouseEvent.MOUSE_DOWN, leftbutton3pressed);

                 

                function leftbutton3pressed(event:MouseEvent){
                    gotoAndStop("page4");
                }

                 

                leftbutton4.addEventListener(MouseEvent.MOUSE_DOWN, leftbutton4pressed);

                 

                function leftbutton4pressed(event:MouseEvent){
                    gotoAndStop("page5");

                 

                   
                }

                 

                So if I use the NEXT/PREVIOUS BUTTON from any other page it works perfectly but not if I click the button on KEYFRAME 1. If I add nextbutton.visible = false;  at the end of the above code I get Error 1120: Access of undefined property next button.

                 

                Any help gladly recieved.

                 

                Thanks

                 

                George

                • 5. Re: Hiding the "Next" Button AS3
                  Ned Murphy Adobe Community Professional & MVP

                  If the next button is inside another object (navbar), then you need to target it thru that using the instance names...

                   

                  navbar.nextbutton.visible = false; // for example

                  1 person found this helpful
                  • 6. Re: Hiding the "Next" Button AS3
                    thefab4 Level 1

                    Hi Ned

                     

                    Didn't work I'm afraid.

                     

                    The NEXTBUTTON symbols is nested inside a MC called PAGESNAVBARCONTENTS which in turn is nested inside an MC called PAGESNAVBAR.

                     

                    I've tried:

                     

                        pagesnavbarcontents.nexbutton.visible = false;

                     

                     

                    and

                     

                        pagesnavbar.pagesnavbarcontents.nexbutton.visible = false;

                     

                     

                    but to no avail - still getting 1120: Access of undefined property pagesnavbarcontents.

                     

                    Am I putting it in the wrong place or does the NEXTBUTTON need to be called in some way.

                     

                    I'm sorry I started this project so if you are getting fed up helping I will understand.

                     

                    Thanks in anticipation.

                     

                    George

                    • 7. Re: Hiding the "Next" Button AS3
                      Ned Murphy Adobe Community Professional & MVP

                      The error is indicating the object you are targeting doesn't exist where that code is... which could be a case of it being in another frame or mis-spelled, or other similar MIA scenarios.

                      1 person found this helpful