5 Replies Latest reply on Apr 20, 2011 1:59 PM by Ned Murphy

    Operating Buttons within a Movie clip

    HeroSense

      I am building a website in flash for a design class (emphasis on design, nothing taught with actionscript)

       

      I need help trying to figure out the actionscript for allowing buttons inside a movie clip symbol to navigate pages at the parent/root/main timeline level.

       

      With this site I have the mainMenu as a Movie Clip symbol and have the menu items populate with animation inside the movie clip.  I need these buttons when pressed to navigate to different parts of the site that are controlled on the main level of the site (outside of the movie clip the buttons reside in).

       

      I have given the buttons instance names, btnDining in the movie clip symbol.  The movie clip symbol is call mainMenu.  In the main level, I have labels for the different states/pages I want the website to have (dining, accommodations, etc)

       

       

      I have tried making the code work inside the mainMenu movie clip symbol when all the buttons are loaded:

       

      btnDining.addEventListener(MouseEvent.CLICK, dining);
      function dining(evt:Event):void {
          gotoAndStop("dining");   
      }

       

      Nothing happens when I click this, I imagine because the gotoAndStop("dining") is not in the movie clip but on the main stage/level of the flash.

       

       

       

      I also tried calling the buttons from the main stage/level after everything I need is loaded:

       

      mainMenu.btnDining.addEventListener(MouseEvent.CLICK, dining);
      function dining(evt:Event):void {
          gotoAndStop("dining");   
      }

       

      When I launch the test, I get this in the output section:

      "Error #1009: Cannot access a property or method of a null object reference."

       

      Nothing happens when I click this either, I think it has to do with the mainMenu not being a valid reference.

       

       

      I don't know if it is best to run the code from inside the movie clip symbol and call the different view on the main stage/level of the flash or if I try to run from the main stage/level and reference the buttons inside the movie clip symbol.

       

      Please help me figure this out, I am trying to go a little above and beyond on this project.  I have been struggling on this for days and I have looked at tutorials, books I have on actionscript, etc.  Please reccommend the best course of action and what actionscript I need to make this work.

       

      Thanks so much

        • 1. Re: Operating Buttons within a Movie clip
          Ned Murphy Adobe Community Professional & MVP

          Your second approach will probably be a cleaner one in terms of directing the timeline intended.  For the 1009 error, it basically means that an object your code is targeting does not exist as far as the code sees it.  It maybe a matter of something not having an instance name which can happen a couple of ways...

           

          - you didn't assign it

          - you didn't assign it in every keyframe of that object prior to the frame that has that code

          1 person found this helpful
          • 2. Re: Operating Buttons within a Movie clip
            HeroSense Level 1

            I still get the error:

             

            TypeError: Error #1009: Cannot access a property or method of a null object reference.

             

            this is the line that is causing the error according to a debug run:

             

            mainMenu.btnDining.addEventListener(MouseEvent.CLICK, dining);

             

            mainMenu is the instance name of the movie clip symbol

            btnDining is the instance name of the button inside of mainMenu

             

            Any additional insights?  Do I need to declare the variables in the actionscript outside of filling out the instance name in the properties window, if so, how?

            • 3. Re: Operating Buttons within a Movie clip
              Ned Murphy Adobe Community Professional & MVP

              Before that line of code use:

               

              trace(mainMenu, mainMenu.btnDining);

               

              If one of those comes up undefined, that's the object that doesn't exist as far as your code is concerned.  To resolve it you will need to provide details of how you have implemented the object into the timeline.

              1 person found this helpful
              • 4. Re: Operating Buttons within a Movie clip
                HeroSense Level 1

                I put in your trace statement from above and ran the debug test again and the only additional thing I get is this line:

                 

                [object mainMenuBackgroundGraphic_2] null

                 

                I got a mainMenuBackgroundGraphic in my library but I don't know what the _2 means.

                 

                Thanks for your help.

                • 5. Re: Operating Buttons within a Movie clip
                  Ned Murphy Adobe Community Professional & MVP

                  If that's the output you get, it looks like your btnDining button is the missing culprit.  You need to make sure that it has that instance name assigned in every keyframe it is in, and that it is present when that code executes.  If it is somewhere down a timeline inside the movieclip, it is not present.