3 Replies Latest reply on Aug 24, 2014 10:16 AM by robdillon

    Multiple Similar Buttons: Copy, Duplicate, Class, Layer?

    tomihasa

      I have Main Scene where you can navigate clicking simple text buttons I have created. The buttons look the same except the text is different i.e. "Scene 2" and "Scene 3". On Scenes 2 and 3 I use the same back button, which is vector graphics made from lines and a rectangle.

       

      What is the best practise using the same button to create the other buttons? Should I duplicate the button or copy paste it? Should I have a new layer for each button? Should I create a custom class for the button?

       

      Below is the code I'm using on each scene:

       

       

       

       

      // MAIN SCENE

      // ----------

       

      stop();

       

      // LISTENERS

       

      scene2Button.addEventListener( MouseEvent.CLICK, toScene2 );

      scene3Button.addEventListener( MouseEvent.CLICK, toScene3 );

       

      // FUNCTIONS FOR THIS SCENE

       

      function toScene2( event ) {

        gotoAndStop( 1, "Scene 2" );

      }

       

      function toScene3( event ) {

        gotoAndStop( 1, "Scene 3" );

      }

       

      // FUNCTIONS FOR OTHER SCENES

       

      function toMainScene( event ) {

        gotoAndStop( 1, "Main Scene" );

      }

       

       

       


       

       

       

      // SCENE 2

      // -------

       

      stop();

       

      // LISTENERS

       

      backButton.addEventListener( MouseEvent.CLICK, toMainScene );

       

       

       


       

       

       

      // SCENE 3

      // -------

       

      stop();

       

      // LISTENERS


      backButton.addEventListener( MouseEvent.CLICK, toMainScene );

       

       

      And here are the .fla, .swf and other files I have created:

       

      Navigation Example

        • 1. Re: Multiple Similar Buttons: Copy, Duplicate, Class, Layer?
          robdillon Most Valuable Participant

          1. Don't use "scenes". There are many, many, reasons why scenes are problematic. There are NO good reasons to use scenes. If you are going to use the timeline to lay out your movie, just use frame labels to delineate sections of the movie.

          2. You can create a single button movieClip and use as many instances of it as you need in your movie. To differentiate the buttons, you can set a layer with a dynamic text field to hold the label for the button, or you can set the label outside of the button, on the side, for instance. You cannot put a dynamic text field in a button object, only a movieClip. If you only have a few buttons and you use vector graphics, you shouldn't have a problem with file size, so what you have will work fine.

          3. Use as many layers as you need to keep your objects sorted out. There is no file size difference between a movie with 100 layers and one with only 1 layer.

          4. Creating classes for your code makes sense if you are working on a complex project, or you are working with a group of software developers who are sharing code, or if you are using code that will be used for many projects. If you want to create classes for your project, go ahead, but it won't make your movie run any better or reduce the size of the file.

          1 person found this helpful
          • 2. Re: Multiple Similar Buttons: Copy, Duplicate, Class, Layer?
            tomihasa Level 1

            Rob Dillon. You gave me something to think about with the «Don't use "scenes".»

             

            Adobe says "Rather than working with scenes created in the Scenes panel, consider using movie clips or jumping to frames in the main Timeline instead." http://www.adobe.com/devnet/flash/articles/efficiency-tips.html

             

            I'm going to teach programming with my Flash project, and I just can't find another way comfortable to me of taking the project to pieces. I'm thinking of a main scene where you can select what you want to learn, like commenting, control statements (if, while), methods (static), arrays, classes, inheritance, exception handling (throw, catch) and so on. You press buttons or links to get to the other sections. The pages mainly consist of text and code examples. I might add a quiz as the last scene perhaps with some animations.

             

            Any suggestions on how to use Movie Clips on that, because using a lot of frames means I would have to scroll to right and left all the time? I'm new to Flash, so I'm still experimenting and pondering my options.

            • 3. Re: Multiple Similar Buttons: Copy, Duplicate, Class, Layer?
              robdillon Most Valuable Participant

              There are many methods for using movieClips.

              1. One, simple, way to use movieClips is to create each new block of content as its own movieClip.So the commenting content, for instance, would be built in its own movieClip. Then you can place that movieClip in its own layer on the timeline. Make the movieClip's visibility property false. Then, when you want to play, that content, make the movieClip visible. If this new movieClip is in a layer higher than the existing content, it will show up. Alternately you can make the earlier content not visible, and then it doesn't matter which layer contains what content. You turn on one layer's content and the other content off.

              2. Again, create each block of content as its own movieClip. Don't put the movieClip on the timeline, just leave it in the Library. Set the movieClip to be exported for Actionscript, and give it an instance name. Then you can use addChild() and/or removeChild() to show and hide the movieClips in the Library.

              3. Instead of creating movieClips for each section, create individual movies for each block of content. Then you can load in the new content and use it as you need it.

              1 person found this helpful