5 Replies Latest reply: Feb 5, 2010 10:44 AM by Ned Murphy RSS

    Need Button code.

    Rich146 Community Member

      I know this is embarrassingly basic and I have done it before but my old brain cannot figure it out today.

      In AS2 I need code for a button, on the main timeline, to go to a frame in a mc off the main time line. I have attached a picture of the time lines in case I have not articulated my needs well.

       

      Thank youbutton code .gif

      Rich Gilman

        • 1. Re: Need Button code.
          Ned Murphy CommunityMVP

          Hi Rich, hope all is well for you.

           

          Where is the button?  It needs to be in the same vicinity as the movieclip if you want to have the button coded to command it.  That is, the code needs to be in a frame where both the button and the movieclip exist (separate layers is fine but same frame).

           

          You can place the code for it in the main timeline where the button is as long as it has an instance name as well (let's say it's called "btn"...

           

          btn.onRelease = function(){

               flower2.gotoAndPlay("index");

          }

           

          You can also attach the code to the button, but it's not a recommended practice, so I'll withhold on that for the moment.

          • 2. Re: Need Button code.
            Rich146 Community Member

            Hey Ned. I am well, good to hear from you. David is on vacation and I am lost. I am authoring a new online medical class which I believe will be popular. Even though I spend 40+ hrs a week in front of Flash I still cannot program. I think my brain is missing something.....sort of like asking a color blind person to pick out the red ball...they can't cause they are deficient in the color area of their brain.

            I am still attaching code to buttons....yes...David has been trying to steer me away and maybe I'll start now with your code.

             

            The button is on the main time line and I want it to point to a frame on a mc (wildflower_tut_mc, instance name:wildflower_tut_mc)  residing in the main timeline. The frame is ("Index").

             

            The mc names above are a bit different than what I posted.

             

            Let me know if you need more info.

             

            I tried to use the code you provided but could not get it to work.The button has a instance name of tutbtn

             

            tutbtn.onRelease = function(){

              wildflower_tut_mc.gotoAndStop("index");

            }

             

             

             

            Thanks

            Rich

            • 3. Re: Need Button code.
              Ned Murphy CommunityMVP

              That code you show should work so long as the code and the button and the movieclip are all lined up in the same frame.  Be sure the instance names are assigned at every keyframe those objects occupy. If you still have a problem, if you attach your file (and it's not a CS4 file) I'll take a look at it.

              • 4. Re: Need Button code.
                Rich146 Community Member

                This is the error I get. "Statement must appear within on handler"

                 

                I put the code on the same frame as the button ans mc. remember..."color blind"

                 

                If this does not make sense I will send the file

                • 5. Re: Need Button code.
                  Ned Murphy CommunityMVP

                  That error indicates you were trying to place the code on the button rather than in the frame.  Before you put the code in the actions panel be sure that the last thing you clicked was the keyframe and not the button.