5 Replies Latest reply on Mar 12, 2012 5:19 PM by kglad

    Code on buttons within MC does not work

    TheInXorable

      (Flash CS5, Actionscript 2.0)

       

      Hello all,

       

      I've been having a very frustrating problem. I have two buttons, one to go to the next scene and one to go to the first scene of my game. The problem I've found is that any code, ANYTHING I put within an on (release) or a buttonname.onRelease = function() in the main timeline does not work at all.

       

      The button states (up, over, down) work and display correctly. When I click, it shows the down state, as it should. However, any code that is on them does not run. currently I have this on the main timeline:

       

      mcname.onEnterFrame = function() {

           button1name.onRelease = function() {

                trace("this should work");

           }

           button2name.onRelease = function() {

                trace("this should work");

           )

      )

       

      Neither trace ever shows up. I really want the code to be (on the buttons):

       

      on (release) {

           nextScene();

      }

       

      but that just doesn't want to work, no matter if I put _root. or _level0. or whatever before the nextScene tag.

       

      I have tried it many, many other ways as well. I have tried putting this function on the mc, I have put the code directly on the buttons, and NOTHING WORKS. It's very, very frustrating.

        • 1. Re: Code on buttons within MC does not work
          kglad Adobe Community Professional & MVP

          on your main timeline, assign an instance name to your movieclip (eg, mcname) (in the properties panel) and on mc's timeline, assign an instance name to your button (eg, button2name) (again, in the properties panel).

           

          assign labels to the main timeline frames you want use for navigation (eg, "first scene").  on your main timeline you can then use:

           

          mcname.button2name.onRelease=function(){

          gotoAndStop("first scene");

          }

          • 2. Re: Code on buttons within MC does not work
            TheInXorable Level 1

            Thank you for your prompt reply. I've done as you suggested and it still didn't work. I think the problem may stem from the way I set up the stage. I have every movie clip involved in the scene attached to the stage via the attachMovie() actionscript command. That's how I gave them instance names. I'm not sure if that interferes with referencing the buttons. I have the buttons attached like this:

             

            (scoresign is the mc that houses nextlevelbutton and mainmenubutton)

             

            scoresign.attachMovie("nextlevelbutton", "nextlevelbutton", _root.getNextHighestDepth(), {_x:126, _y:300});

            scoresign.attachMovie("mainmenubutton", "mainmenubutton", _root.getNextHighestDepth(), {_x:35, _y:300});

             

            I don't know if that's enough to go on, but I appreciate any help you can offer.

            • 3. Re: Code on buttons within MC does not work
              kglad Adobe Community Professional & MVP

              i'm assuming your buttons are movieclip buttons.  if so, use:

               

               

               

              scoresign.attachMovie("nextlevelbutton", "nextlevelbutton", scoresign.getNextHighestDepth(), {_x:126, _y:300});

              scoresign.attachMovie("mainmenubutton", "mainmenubutton", scoresign.getNextHighestDepth(), {_x:35, _y:300});

               

              scoresign.nextlevelbutton.onRelease=function(){

              gotoAndStop("first scene");

              }

              scoresign.mainmenubutton.onRelease=function(){

              // do whatever

              }

              • 4. Re: Code on buttons within MC does not work
                TheInXorable Level 1

                That's what I have. I'm not a novice with actionscript, I'm really surprised this is giving me so much difficulty. Still, no code I place within those functions does anything. The button over and down states still work, though. It really doesn't make any sense to me.

                • 5. Re: Code on buttons within MC does not work
                  kglad Adobe Community Professional & MVP

                  kglad wrote:

                   

                  i'm assuming your buttons are movieclip buttons.  if "nextlevelbutton" is not the linkage id of a movieclip, your code makes no sense.  if it is a movieclip over and down states wouldn't work unless you had code elsewhere.

                   

                   

                   

                  scoresign.attachMovie("nextlevelbutton", "nextlevelbutton", scoresign.getNextHighestDepth(), {_x:126, _y:300});

                  scoresign.attachMovie("mainmenubutton", "mainmenubutton", scoresign.getNextHighestDepth(), {_x:35, _y:300});

                   

                  scoresign.nextlevelbutton.onRelease=function(){

                  gotoAndStop("first scene");

                  }

                  scoresign.mainmenubutton.onRelease=function(){

                  // do whatever

                  }