13 Replies Latest reply on Apr 2, 2014 10:05 PM by quenablues

    Problems coding a button within a movie clip to navigate scenes

    Christine Ewert

      Hello there! I've got another probably noobish question to ask about CS6.

       

      My goal is very similar to the one mentioned in this previously discussed forum question: http://forums.adobe.com/message/837995#837995 and also in this question http://forums.adobe.com/message/4172919#4172919

       

      I am attempting to make a button inside a movie clip in my first scene go when clicked to the first frame of my second scene. I named the button's instance menu_button_1 and I believe Scene 1 and Scene 2 are the names of the scenes. (If they should have special names or instance names, I did not see where to type them.) Because of the similarities, I attempted to follow the suggestions on those pages. However I probably did some small thing wrong, (Or heck, maybe a huge thing.) which I what I'd like help with to find.

       

      stop();
      myButton.addEventListener(MouseEvent.CLICK, clickHandler);
      function clickHandler(evt:MouseEvent):void {
      gotoAndStop(1, "Scene 1");
      }

       

      This seemed to be what was suggested to enter. I attempted to modify it to work for me as well. This is what I typed for the button's action.

       

      menu_button_1.addEventListener(MouseEvent.CLICK, clickHandler);

      function clickHandler(evt:MouseEvent):void {

      gotoAndPlay(1, "Scene 2");

      }

       

      (I removed the stop function because I have music looping in the movie clip that I want to play until the mouse is clicked.) (Also, I picked gotoandplay because I wanted scene 2 to start playing immediately when clicked rather than stopping.)

       

      I tried variations, including "2" instead of "scene 2" and whatnot. I also tried linking it to differnet places just to see if that would work. It seems like it could link if I only asked for a frame within the movie clip itself, but it couldn't go to any other frames in scene 1 or scene 2. When I attempt, this message is displayed in the output:

       

      ArgumentError: Error #2108: Scene 2 was not found.

          at flash.display::MovieClip/gotoAndPlay()

          at interactivestgermant_fla::menu_1/clickHandler()

       

      It seems it cannot find my Scene 2. (It also cannot seem to find Scene 1 when I prompt it to do that.) I'm afraid I'm not sure of what I've entered incorrectly, though I'd imagine it involves how I typed the scene navigation. Should it have an instance name or something? I'd very muchappreciate a push in the right direction. If you need any more info I'll be happy to provide it. Thanks for the help! I very much appreciate it.

        • 1. Re: Problems coding a button within a movie clip to navigate scenes
          Ned Murphy Adobe Community Professional & MVP

          If the button is inside a movieclip then the code you showed would have to be in the movieclip's timeline in order to target the button, and if that is the case then you cannot target to main timeline the way you did.  If the code is inside the movieclip then...

           

          gotoAndPlay(1, "Scene 2");

           

          is trying to tell the movieclip to go to frame 1 of scene 2, and movieclips do not have scenes.

           

          What you should do is keep tat code in the main timeline and target the button thru the movieclip, as in....

           

          movieclipName.menu_button_1.addEventListener(MouseEvent.CLICK, clickHandler);

           

          function clickHandler(evt:MouseEvent):void {

                gotoAndPlay(1, "Scene 2");

          }

           

           

          This way the gotoAndPlay line is talking to the main timeline where it will be able to find the other scenes.  Just be sure to assign the names to the objects so that the code is targeting them correctly.

          1 person found this helpful
          • 2. Re: Problems coding a button within a movie clip to navigate scenes
            Christine Ewert Level 1

            Ah, ok. That seems to make more sense. However I get this error:

             

            1120: Access of undefined property menu.

             

            when I attempted to type:

             

            menu.menu_button_1.addEventListener(MouseEvent.CLICK, clickHandler);

            function clickHandler(evt:MouseEvent):void {

             

                  gotoAndPlay(1, "Scene 2");

             

            }

             

            I typed the movieclipName as "menu" becuase that is what I named the movie clip in scene 1 in which this button is inside of. It still doesn't seem to be linking to the first frame of scene 2. Did I fail to assign a name ot a particular object necessary for the code to target scene 2?

            • 3. Re: Problems coding a button within a movie clip to navigate scenes
              Ned Murphy Adobe Community Professional & MVP

              It has an issue targeting the object you are identifying as "menu".  Somehow you have misnamed it.  Make sure you have the name assigned in the Properties panel in any keyframe where the menu object is.

              1 person found this helpful
              • 4. Re: Problems coding a button within a movie clip to navigate scenes
                Christine Ewert Level 1

                I bet you're absolutely right. However I am not sure how I am misnaming it, as to my ametuer eyes, it seems to be entered properly into the properties box? It does show up as "menu" written in white over the keyframes and also in the properties slot. I can include some images here to help out in correcting me.

                 

                http://girlfoxgirl.deviantart.com/art/Flash-Help-1-395704638   This image shows my movie clip. This seems to be the problem it's having, identifying "menu." Did I do that incorrectly? It looks to be in order.

                 

                http://girlfoxgirl.deviantart.com/art/Flash-Help-2-395704633 This is inside of the movie clip named menu. You can see I did the same to name the button menu_button_1.

                 

                http://girlfoxgirl.deviantart.com/art/Flash-Help-3-395704627   This shows the action I gave to menu_button_1 in which I attempt to have it naviagte to Scene 1 frame 493.

                 

                http://girlfoxgirl.deviantart.com/art/Flash-Help-4-395704623  This shows where I'd like the button to go to. (It is hard to tell if that's frame 493 or 492. I figured that it should be ok either way and if this frame is 492 then it's easily changed once I get the darn thing working in general) (Also, I named the layer "peanuts." I tired entering the name "peanuts" as well but it didn't seem to work either, so I figured "493" is easier since I know that you can go to a specific frame by doing gotoandplay("scene 1" , #) and I'm not sure if it requires any additional stuff to go to a name.

                 

                http://girlfoxgirl.deviantart.com/art/Flash-Help-5-395704687    These are the errors I get. I totally agree with you- It seems very much to be an issue of getting it to recognize the "menu." However I am unsure where I named something wrong. Is this enough info to help you perhaps point out where that is?

                • 5. Re: Problems coding a button within a movie clip to navigate scenes
                  Ned Murphy Adobe Community Professional & MVP

                  The first image you provided shows that you have assigned a frame label, not an instance name.  You need to select the menu object on the stage and then you should see a section of the Properties panel at the very top that has a field with "<Instance Name>" indicated inside it (assuming it is a movieclip symbol).  That is where you enter the word "menu"... that is assigning a name to the instance of the menu that you have on the stage.

                   

                  The way you appear to have a number of keyframes preceding it in the timeline might mean you need to do this in every keyframe where that menu object exists.  IF you don't, then it can inherit the lack of a name from a preceding frame.

                  • 6. Re: Problems coding a button within a movie clip to navigate scenes
                    Christine Ewert Level 1

                    Ah, thank you. I was wondering, but I didn't know to click the stage to get at it. You were quite right. I failed to enter the instance name. However I did and named it menu (changing the keyframe label in case there would be a problem naming two things the same name.) and I still got the same error message as last time. It still doesn't recognize root or menu.

                     

                    http://girlfoxgirl.deviantart.com/art/Flash-Help-6-395783991  Here i an image of the instance name. I believe I followed your last instructions by selecting all of the move clip before changing the instance name.

                     

                    http://girlfoxgirl.deviantart.com/art/Flash-Help-7-395784804 I believe I thankfully did the correct thing and got the menu button's instance name as menu_button_1

                     

                    So... I'm a bit confused still as to why entering this: http://girlfoxgirl.deviantart.com/art/Flash-Help-3-395704627  still results in this: http://girlfoxgirl.deviantart.com/art/Flash-Help-5-395704687  if I have the proper instance name for the menu now.

                     

                    Also, should I be doing something with the root command? Should it read something else, or does it require an instance name somewhere? Thanks for all your help by the way. ^^; The least I can do is upvote your comments.

                    • 7. Re: Problems coding a button within a movie clip to navigate scenes
                      Ned Murphy Adobe Community Professional & MVP

                      I can only guess that you have a number of problems with how you are doing things.

                       

                      1) In the first image you show what I'll assume is the menu object selected since its instance name is showing, but I do not see any code in the vicinity.  So I'd have to guess that the code is somewhere else (some other frame) where that menu object doesn't exist.

                       

                      2) For the second image, you say you named the button menu_button_1, but that is not how I see it spelled in the image... the image shows it with a capital "M" which will matter.

                       

                      3) For the image with the code, it looks like I am still looking at the image with the button, which should be inside the menu.  If that code is inside the menu, it cannot be targeting the menu... it is looking for something inside that timeline that is named menu.  To target the menu you need to be in the timeline that holds it.

                       

                      4) Same code image, I do not know what you are calling "root_".  If it is not some other object that you have assigned an instance name to, then I'll guess the intention is that it is trying to target the main (root) timeline to tell it to go to some frame.  If that's the case it is called "root", and it has to be targeted using "MovieClip(root)"....

                       

                      If it does happen to be some object that you have assigned an instance name of "root_" to, then that object cannot possibly contain any scenes, so targeting a scene in the gotoAnd... command is wrong.

                       

                      If it does happen to be trying to target the root timeline, then it is still coded incorrectly because in AS3 the scene is the second argument, not the first (the opposite of how AS2 does it).

                       

                      You might to to revisit my first response regarding where the code oughta go for the way you are now trying to target things.

                       

                       

                      Did you know you can implant images in your posting rather than having links to external sites?  It helps to not have to link elsewhere.  That little camera icon in the toolbar is what does it.

                      1 person found this helpful
                      • 8. Re: Problems coding a button within a movie clip to navigate scenes
                        Christine Ewert Level 1

                        Aw,sweet, man! Thanks for being so thorough. I fixed those many errors and got just what I'd hoped: the button does seem to work now. Thanks once again!

                        • 9. Re: Problems coding a button within a movie clip to navigate scenes
                          Christine Ewert Level 1

                          Hello there again!

                           

                          I was doing this same type of thing a second time. In the first, it works perfectly. The button inside of a movie clip in scene one goes to the first frame in scene 2. However, I tried duplicating this same type of thing to make a button in a movie clip in scene 2 go to the first frame in scene 3. However, though I entered the unique movie instance name and button instance name just like I did for the first working button only for the new button and new movie clip, it doesn't seem to work. Not only that, it seems to have affected the first buttom. When I delete the new button's action entirely, the first button works to get to scene 2. However when I enter the action onto the new button, when I play the first button no longer goes to scene 2 at all. Do I need to give the function a new name to make sure the second action doesn't go to the first? Sorry, I'm not sure which word is a name I should change since they look important to the fuction of the button. I figured making the second button has interferred with the first button anyway. The error I get is "duplicate function definition." The first button's action is this:

                           

                          menu.Menu_button_1.addEventListener(MouseEvent.CLICK, clickHandler);

                           

                          function clickHandler(evt:MouseEvent):void {

                           

                                 gotoAndPlay(1, "Scene 2");

                          }

                           

                          Andthe second button's is this:

                           

                          ohsceneclip.oh_scene_next.addEventListener(MouseEvent.CLICK, clickHandler);

                           

                          function clickHandler(evt:MouseEvent):void {

                           

                                 gotoAndPlay(1, "Scene 3");

                          }

                           

                          Which part should I change, sorry? Thanks very much, man.

                          • 10. Re: Problems coding a button within a movie clip to navigate scenes
                            Ned Murphy Adobe Community Professional & MVP

                            Yes, you should not name functions the same... if you do you will get that duplicate function error.  How could the code know which to use?  YOu can make up any name you like (pretty much) and it can help to name the function relative to what the function does.

                            1 person found this helpful
                            • 11. Re: Problems coding a button within a movie clip to navigate scenes
                              Christine Ewert Level 1

                              Alrighty, thanks. Would "clickhandler" be the function name I'd change, however? I attempted to change that and while it didn't affect the original button any loner the second button seems to go nowhere and I get this message from theoutput tab rather than the compiler error tab.

                               

                              TypeError: Error #1010: A term is undefined and has no properties.

                                  at interactivestgermant_fla::MainTimeline/frame493()

                                  at flash.display::MovieClip/gotoAndPlay()

                                  at interactivestgermant_fla::MainTimeline/clickHandler()

                               

                              Was that not the proper way to change the function name? Or is this an error due to another one of my mistakes?

                               

                              Here was the action for the second button again:

                               

                              ohsceneclip.comeinnext.addEventListener(MouseEvent.CLICK, clickHandler2);

                               

                              function clickHandler2(evt:MouseEvent):void {

                               

                                     gotoAndPlay(1, "Scene 3");

                               

                              }

                               

                              Thanks again in advance, man.

                              • 12. Re: Problems coding a button within a movie clip to navigate scenes
                                Christine Ewert Level 1

                                Whoops, I did seem to find the problem with frame 493. Random action got put there. But the rest I'm still curious about! ^^; My bad!

                                • 13. Re: Problems coding a button within a movie clip to navigate scenes
                                  quenablues

                                  I´ts true problem solved too, movieclipname.buttonname  its the correct way for call this buttons inside movie clip