10 Replies Latest reply: Oct 22, 2009 10:04 AM by Ned Murphy RSS

    Creating Navigation with Actionscript 3

    mariahleigh33 Community Member

      So I have created all new movie clips in my index.fla file by copying all of my files from another file and pasting them into the movie clip  timeline. I have placed all of my new movie clips in different layers on the index timeline, and have created keyframes 10 frames apart. I have my actions layer with frame labels for each page every ten frames (i.e. tbLabel is at frame 1 in my actions layer and the movie clip is on a different layer at frame one, restaurantLabel is at frame 10 in my actions layer and the movie clip for that page is on a different layer at frame ten, all the way up to frame 120). I haven't put any actionscript in my movieclips except for stop(); at the end of each file. My current actionscript, placed in frame 1 for my first page when the viewer goes to the site is as follows:

       

       

      thunderBayBtn.addEventListener(MouseEvent.CLICK, goIndex);

      restaurantBtn.addEventListener(MouseEvent.CLICK, goRestaurant);

      birchBtn.addEventListener(MouseEvent.CLICK, goBirch);

      menuBtn.addEventListener(MouseEvent.CLICK, goMenu);

      eventBtn.addEventListener(MouseEvent.CLICK, goEventLand);

      davEventBtn.addEventListener(MouseEvent.CLICK, goDavEvent);

      rockEventBtn.addEventListener(MouseEvent.CLICK, goRockEvent);

      pewEventBtn.addEventListener(MouseEvent.CLICK, goPewEvent);

      pewEventBtn.addEventListener(MouseEvent.CLICK, goPewEvent);

      giftBtn.addEventListener(MouseEvent.CLICK, goGiftCert);

      downloadBtn.addEventListener(MouseEvent.CLICK, goDownload);

      contestBtn.addEventListener(MouseEvent.CLICK, goContestLand);

      davContestBtn.addEventListener(MouseEvent.CLICK, goDavContest);

      rockPewContestBtn.addEventListener(MouseEvent.CLICK, goRockPewContest);

       

      function goIndex(event:MouseEvent):void

      {

                  gotoAndPlay(1);

      }

       

      function goRestaurant(event:MouseEvent):void

      {

                  gotoAndPlay(10);

      }

       

      function goBirch(event:MouseEvent):void

      {

                  gotoAndPlay(20);

      }

       

      function goMenu(event:MouseEvent):void

      {

                  gotoAndPlay(30);

      }

       

      function goEventLand(event:MouseEvent):void

      {

                  gotoAndPlay(40);

      }

       

      function goDavEvent(event:MouseEvent):void

      {

                  gotoAndPlay(50);

      }

       

      function goRockEvent(event:MouseEvent):void

      {

                  gotoAndPlay(50);

      }

       

      function goPewEvent(event:MouseEvent):void

      {

                  gotoAndPlay(50);

      }

       

      function goGiftCert(event:MouseEvent):void

      {

                  gotoAndPlay(90);

      }

       

       

      function goDownload(event:MouseEvent):void

      {

                  gotoAndPlay(100);

      }

       

      function goContestLand(event:MouseEvent):void

      {

                  gotoAndPlay(110);

      }

       

      function goDavContest(event:MouseEvent):void

      {

                  gotoAndPlay(120);

      }

       

      function goRockPewContest(event:MouseEvent):void

      {

                  gotoAndPlay(120);

      }

       

       

       

       

      However, when I go to test the movie, I get "1120 access" errors even though the buttons are named in the properties pane, however, I cannot view that in the file that conatins all of my movie clips because they are movie clips.

      Also, When I go to view the movie with all of my movie clips, all of them play one on top of the other, none of them stop, and the buttons do not work.

       

      Is this the correct Actionscript?

       

      I'm having a hard time figuring out what actionscript I need to use and where!

        • 1. Re: Creating Navigation with Actionscript 3
          Ned Murphy CommunityMVP

          If you are getting errors, then your file will not run correctly, so don't expect it to behave properly.  If you go into your Flash Publish Settings and enable Permit Debugging, you will get a little more information in your error messages, such as line numbers following the frame numbers.  And it always helps to show the actual messages in your postings.

           

          Do you have a stop(); command in frame 1?  Are all of your buttons present and instance-named in frame 1?  It's not clear what you intend at each frame of the main timeline, but it sounds like you should be using gotoAndStop() commands for your button functions instead of gotoAndPlay().

          • 2. Re: Creating Navigation with Actionscript 3
            mariahleigh33 Community Member

            This is the error I am getting:

            1120: Access of undefined property contestBtn.

            • 3. Re: Creating Navigation with Actionscript 3
              mariahleigh33 Community Member

              It is doing this for all of my buttons, my actions are located in frame one of my index.fla file that contains all the movie clips which have the buttons. I have no actionscript in the movie clips except for stop(); at the end of each clip.

               

              I did not put any code into each movie clip because if I put goToAndPlay(40); it would go to frame 40 of the movie clip and not frame 40 of my main file that contains that movie clip. Is that correct?

               

              I have created my one main file so that I can link all of my movie clips, which are my different pages to my website, and all of my button names are defined in the properties panel in each movie clip, however I believe that I am getting the error because the name is defined in the movie clip and my movie clips are embedded into the main file so it is not finding the name. Could that be the problem?

               

              Thanks

              • 4. Re: Creating Navigation with Actionscript 3
                Ned Murphy CommunityMVP

                You have me confused. You say the movieclips are spread out on the timeline, then you say your buttons are inside the movieclips.  How can you access the buttons if they are not all together to be chosen?  In any case, if your buttons are inside the movieclips, then you need to target them inside the movieclips...  Assume you have a button named aButton inside aMovieclip... to target that button to assign an event listener to it from the main timeline you would use...

                 

                aMovieclip.aButton.addEventListener(...etc)

                 

                But that button needs to exist where that code executes, so if that code is in frame 1 of the main timeline, then that movieclip needs to exist in frame 1 of the main timeline, and that button needs to exist in frame 1 of the movieclip.

                • 5. Re: Creating Navigation with Actionscript 3
                  mariahleigh33 Community Member

                  Thanks! I will try that, that makes sense.

                  • 6. Re: Creating Navigation with Actionscript 3
                    mariahleigh33 Community Member

                    Ok so this is what I did in frame one for each of my buttons:

                     

                    indexPage.thunderBayBtn.addEventListener(MouseEvent.CLICK, goIndex);

                     

                    Thant made my indexPage movie clip play all of the way through, which never happened before. When I click on the buttons though, it does not go to the frame that I specified. Also, I put the same code but changed it to:

                     

                    restaurantPage.thunderBayBtn.addEventListener(MouseEvent.CLICK, goIndex);

                     

                    so that I could call the buttons in the restaurant movie clip to do their job, however I get an error saying that there is duplicate objects. Should I put this code in frame one? Or should I put it in frame 10 where that movie clip is located?

                     

                    So sorry, your help is greatly appreciated!!

                    • 7. Re: Creating Navigation with Actionscript 3
                      Ned Murphy CommunityMVP

                      Reread what I offered regarding where things need to be relative to the code that assigns functionality to them.  As far as duplicates go, your second button is calling the same function, so it sounds like you duplicated the goIndex function, unless that function is determining which button was clicked and taking action based on that (which is possible).  You cannot have two functions defined with the same name.... your buttons can call the same function(s), but separate functios in the same file need different names.

                      • 8. Re: Creating Navigation with Actionscript 3
                        mariahleigh33 Community Member

                        Thanks. Got the duplicate figured out.

                         

                        Now I get an error:

                         

                        TypeError: Error #1009: Cannot Access A Property Or Method Of A Null Object Ref

                         

                        and my buttons won't take me to the scene i ask them to.

                        • 9. Re: Creating Navigation with Actionscript 3
                          mariahleigh33 Community Member

                          I have changed the code to look like this so that it finds the buttons inside the restaurantPage movie Clip:

                           

                          restaurantPage.thunderBayBtn.addEventListener(MouseEvent.MOUSE_DOWN, goRestaurant);

                           

                          Do I need to add some sort of back out to get out of the movie clip back to the main timelines so that it plays at frame 10 on the main timeline?

                           

                          function goRestaurant(event:MouseEvent):void
                          {   
                                  gotoAndPlay(10);
                          }

                          • 10. Re: Creating Navigation with Actionscript 3
                            Ned Murphy CommunityMVP

                            IF that function is on the main timeline, no, as is, the button inside the movieclip will tell the main timeline to goto frame 10 since the function is on the main timeline... everything is coded relative to timelines.