12 Replies Latest reply on Mar 12, 2011 6:15 AM by dgmdeano

    same code not working now?

    dgmdeano

      Hi guys. I'm new to flash and have run into a problem with actionscript. Here's an example of the actionscript I have been using:

       

      stop();

       

       

      home.buttonMode = true;

      home.useHandCursor = true;

       

       

       

      function home_clicked (e:MouseEvent) :void{

       

      gotoAndStop("page0") ;

       

      }

      home.addEventListener (MouseEvent.CLICK, home_clicked);

       

       

      this code was working fine, but by creating a new page which is a gallery with thumbnail buttons (using the same button and actionscript method), when previewed the whole site does not function??

       

      The buttons for the thumbnail images in the gallery are on a different layer to that of the menu box (they are on the pages layer, on a few individual frames), but the actionscript is all on the same layer (actions).

       

      Picture 1.png

       

      Hope this post makes sense and that someone can make sense of this problem? Let me know if more details are needed, cheers

        • 1. Re: same code not working now?
          Ned Murphy Adobe Community Professional & MVP

          Do you get error messages?  Is there a reason you have keyframes at the end of each layer that otherwise stretch the full length of the timeline?  I would expect the menu layer to only have the one keyframe (possibly the others as well, except for the pages layer)

          • 2. Re: same code not working now?
            dgmdeano Level 1

            No errors, only when the actions layer is extended/pulled to the right. The error code is a Duplicate function definition for every frame and line. When it's kept as it is in the screen print it just does not work, but no errors show up.... yet when the new buttons script (using the exact same code) are removed from the actionscript, it works fine again. Which tells me it couls be something to do with them being on a different layer.

             

            Not sure why there's a keyframe there, when I try extending or retracting the length of the frame/s it just leaves a keyframe at the end?

            • 3. Re: same code not working now?
              Ned Murphy Adobe Community Professional & MVP

              For all those layers that you're not sure why they have a keyframe, get rid of the extra keyframes.  Right click them and select Remove Keyframes.

               

              You have some kind of setup problem, though from the screenshot and your description of what's what it is not clear what it could be.   If all your buttons are on a layer that extends uninterrupted along the timeline (only one keyframe on the layer), and the code for the buttons is only in a keyframe in frame 1, then there should be no problem.

               

              If you end up having the same functions in different frames, that will not work.

              1 person found this helpful
              • 4. Re: same code not working now?
                dgmdeano Level 1

                Hey, well the thing is all the buttons aren't on the same layer, they were all on the menu layer, but I created a gallery page and added buttons on it for the thumbnail images in the gallery. These buttons are on the frame which has the gallery page content, on the pages layer.

                • 5. Re: same code not working now?
                  Ned Murphy Adobe Community Professional & MVP

                  Since you said you came to a point where nothing works anymore, then try backtracking and remove things until you get it working again... you don't necessarily have to delete the code, just comment it out.  Then gradually add the code back in and you should then have a better idea of what leads to the problem.

                  • 6. Re: same code not working now?
                    dgmdeano Level 1

                    Yeah good advice! I inserted a blank frame on the above the gallery page, in the actions layer, and pasted the code

                     

                    stop();

                     

                    thumb1.useHandCursor = true;

                    thumb1.buttonMode = true;

                    thumb2.useHandCursor = true;

                    thumb2.buttonMode = true;

                    thumb3.useHandCursor = true;

                    thumb3.buttonMode = true;

                    thumb4.useHandCursor = true;

                    thumb4.buttonMode = true;

                    thumb5.useHandCursor = true;

                    thumb5.buttonMode = true;

                    prev1.useHandCursor = true;

                    prev1.buttonMode = true;

                    prev2.useHandCursor = true;

                    prev2.buttonMode = true;

                    prev3.useHandCursor = true;

                    prev3.buttonMode = true;

                    prev4.useHandCursor = true;

                    prev4.buttonMode = true;

                    nxt1.useHandCursor = true;

                    nxt1.buttonMode = true;

                    nxt2.useHandCursor = true;

                    nxt2.buttonMode = true;

                    nxt3.useHandCursor = true;

                    nxt3.buttonMode = true;

                    nxt4.useHandCursor = true;

                    nxt4.buttonMode = true;

                     

                    function thumb1_clicked (e:MouseEvent) :void{

                     

                    gotoAndStop("image1") ;

                     

                    }

                     

                    function thumb2_clicked (e:MouseEvent) :void{

                     

                    gotoAndStop("image2") ;

                     

                    }

                     

                    function thumb3_clicked (e:MouseEvent) :void{

                     

                    gotoAndStop("image3") ;

                     

                    }

                     

                    function thumb4_clicked (e:MouseEvent) :void{

                     

                    gotoAndStop("image4") ;

                     

                    }

                     

                    function thumb5_clicked (e:MouseEvent) :void{

                     

                    gotoAndStop("image5") ;

                     

                    }

                     

                    function prev1_clicked (e:MouseEvent) :void{

                     

                    gotoAndStop("image1") ;

                     

                    }

                     

                    function prev2_clicked (e:MouseEvent) :void{

                     

                    gotoAndStop("image2") ;

                     

                    }

                     

                    function prev3_clicked (e:MouseEvent) :void{

                     

                    gotoAndStop("image3") ;

                     

                    }

                     

                    function prev4_clicked (e:MouseEvent) :void{

                     

                    gotoAndStop("image4") ;

                     

                    }

                     

                    function nxt1_clicked (e:MouseEvent) :void{

                     

                    gotoAndStop("image2") ;

                     

                    }

                     

                    function nxt2_clicked (e:MouseEvent) :void{

                     

                    gotoAndStop("image3") ;

                     

                    }

                     

                    function nxt3_clicked (e:MouseEvent) :void{

                     

                    gotoAndStop("image4") ;

                     

                    }

                     

                    function nxt4_clicked (e:MouseEvent) :void{

                     

                    gotoAndStop("image5") ;

                     

                    }

                     

                    thumb1.addEventListener (MouseEvent.CLICK, thumb1_clicked);

                     

                    thumb2.addEventListener (MouseEvent.CLICK, thumb2_clicked);

                     

                    thumb3.addEventListener (MouseEvent.CLICK, thumb3_clicked);

                     

                    thumb4.addEventListener (MouseEvent.CLICK, thumb4_clicked);

                     

                    thumb5.addEventListener (MouseEvent.CLICK, thumb5_clicked);

                     

                    prev1.addEventListener (MouseEvent.CLICK, prev1_clicked);

                     

                    prev2.addEventListener (MouseEvent.CLICK, prev2_clicked);

                     

                    prev3.addEventListener (MouseEvent.CLICK, prev3_clicked);

                     

                    prev4.addEventListener (MouseEvent.CLICK, prev4_clicked);

                     

                    nxt1.addEventListener (MouseEvent.CLICK, nxt1_clicked);

                     

                    nxt2.addEventListener (MouseEvent.CLICK, nxt2_clicked);

                     

                    nxt3.addEventListener (MouseEvent.CLICK, nxt3_clicked);

                     

                    nxt4.addEventListener (MouseEvent.CLICK, nxt4_clicked);

                     

                     

                    previewed it and the site worked, but the links did not. Pasted the same full code onto the frames with the full size images on (the ones the thumbnails are linking to) and I got a duplicate function error for it?

                    • 7. Re: same code not working now?
                      Ned Murphy Adobe Community Professional & MVP

                      If you copied and pasted that same code somewhere else, and left it where you had it as well or pasted the same code in different places, you duplicated all the functions, which will generate that error.

                       

                      Your functions all involve gotoAndStop commands.  Are those frame labels on the same timeline as the function(s) code?

                       

                      Where are the buttons for that code and where is that code?... describe it in terms of the image you showed (frames/layers).

                      • 8. Re: same code not working now?
                        dgmdeano Level 1

                        Picture 2.png

                         

                        the new buttons are on this frame. I've tried pasting the actionscript code on this frame/layer and on the actions layer.

                         

                        Not sure what you mean about the frame labels being on the same timeline as the function code sorry.

                        • 9. Re: same code not working now?
                          Ned Murphy Adobe Community Professional & MVP

                          You said you placed the code in the timeline that you show in the picture.  Are the frame labels that you target in that code also on that timeline?

                          • 10. Re: same code not working now?
                            dgmdeano Level 1

                            Yep, all in the same timeline.

                            • 11. Re: same code not working now?
                              Ned Murphy Adobe Community Professional & MVP

                              Unfortunately I have yet to figure out what yiour problem really is and how you have thing arranged.  Here's the best guidance I can give for now...  The code for your gallery buttons needs to be placed in the frame where the buttons appear.  You cannot copy and paste that same code to other frames.  If you need to have your gallery buttons in different frames, then you should create a separate layer for them so that they only have code assigned to them in the first frame (the keyframe) they exist in.

                               

                              Maybe if you create your gallery as a separate movieclip this will be easier for you to manage.  Then it might be more of a case where you are recreating something the resembles your main timeline, but functions as a separate entity and only occupies one frame of the main timeline.

                              • 12. Re: same code not working now?
                                dgmdeano Level 1

                                Aha, I've got it. The buttons weren't all in the same frame after all, I forgot that the "prev" and "nxt" buttons were on the frames with the full size images on. Doh! Thanks a great deal for you help! It always seems to be the most obvious of things with Flash.