27 Replies Latest reply on Dec 31, 2008 10:45 AM by kglad

    Flash movie control buttons

    dstx
      In Flash 8, I want to add a set of buttons from button library to bottom left of my movie
      (begin, stop, pause, play, end) that are visible entire duration of movie.
      What is best way to create such action? With event handlers?
      Do I put each button on a separate layer and add frames from beginning to end of movie ?
      Or can all buttons be on same layer?
      And how do I find/write actionscript code that will control entire movie from any frame for each action: go to beginning or end, stop, pause, or play?
        • 1. Re: Flash movie control buttons
          ihong7
          put a button on the main scene, click the button, action script:

          on(release) {
          play();
          }

          and so on.

          you make a new time line that have the buttons visible thru out the movie
          • 2. Re: Flash movie control buttons
            dstx Level 1
            I don't understand. Can you be more specific?
            I have all buttons on same layer with all frames filled for entire length of movie so all buttons are visible continuously throughout the movie.
            Now, how do I click on any of the five buttons, actionscript??? What does that mean?
            • 3. Re: Flash movie control buttons
              clbeech Level 3
              what ihong7 is saying above is to 'attach' code to each button using the 'on(release)' event handler. in order to do so, you would select one of your buttons, then open the 'actionscript' panel, which is where one writes code. however the above method is not recommended, since attaching code to objects is not considered to be 'good' practice and has been eliminated in more recent versions of AS. instead, one should place your codes on the timeline, to do so, create a new layer called "actions", you will use this layer for all of the necessary code. to enter code, select the first frame of the layer 'actions' and open the actions panel and type in the codes needed. 'actionscript' is the programming language used in Flash and under Flash8 it is actionscript 2.0 - i would also recommend doing some reading in the Flash Help documentation, which will give you a basis to use Flash and code effectively.

              it is fine for the buttons to all be on the same layer, but you will need to give each of them an 'instance name'. to do so select one of the buttons you've placed on the stage, look in the properties panel, on the left side you will see a input field that says <instance name>, type the individual name of the button into the field. this will allow you to 'point' to the instance with your codes.

              to create a 'event handler' that your buttons will respond to you need to specify which event you are using. in this case you are basically going to use the 'onPress' or 'onRelease' handler(s) - personally I prefer the onPress for a few different reasons. so to get your button to 'hear' the click you would use this syntax:

              myButton.onPress = function() {
              trace('myButton has been pressed');
              }

              the 'trace' statement above is only for demonstration and will cause the text to be displayed in the output panel, this is an example of 'how' you can get the event to respond to the click of the mouse - also in the code above we are 'assigning' the event handler to the button with the instance name of 'myButton' - for each button that you have named and is on the stage, you will need to 'point' to that instance using the instance name of each button.

              now, you wish to use the buttons to control the movie playback it appears, so you will need to place code within the event handler's function in order to achieve each of the actions you want the button to perform. to 'stop' the playhead at the current point in the timeline you use the method - stop(); - and to play the timeline from the current point you use the method - play(); - so for instance:

              myStopButton.onPress = function() {
              stop();
              }

              myPlayButton.onPress = function() {
              play();
              }

              to 'pause' the timeline playback, use the stop method - if your wish for the stop button to do something else, you will need to apply a different code.

              to cause the playhead to move to a different part of the timeline - for instance going to the 'end' of the movie - you can use the method: gotoAndStop(); - but you need to indicate 'where' to go to, we can use either a frame number, or a label (another subject) however in this case you can also use another property of the MovieClip class, as below:

              myEndButton.onPress = function() {
              gotoAndStop(_totalFrames);
              }

              the property '_totalFrames' will return a number that represents the last frame of the Main timeline. to go to the beginning or restart the Movie use the number 1 as it is the first frame: gotoAndStop(1);

              this should get you going for now :)
              • 4. Re: Flash movie control buttons
                kglad Adobe Community Professional & MVP
                (wanna bet?)
                • 5. Re: Flash movie control buttons
                  dstx Level 1
                  what do you mean "wanna bet"? if you have a better suggestion, please post instructions, otherwise do not "advertise" in my post.
                  • 6. Re: Flash movie control buttons
                    dstx Level 1
                    What about just skinning the movie with the FLV Component?
                    I created new layer "Controls" above all other layers. Then dragged and aligned the FLV Playback - Player 8 component to that layer and set Parameters in Component Inspector to -
                    autoPlay: false, autoRewind: false, autoSize: false, bufferTime: 0.1, cuePoints: none, isLive: true, maintainAspectRatio: true, skin: ClearExternalAll.swf, skinAutoHide: false, totalTime: 0, volume: 100

                    When I Test Movie in Flash, it plays fine and timing is correct, but there's a space below movie above controller.
                    When I upload to server and test in browser, controller placement is immediately below movie as should be, but audio autostarts and plays ahead of video, progressively worse toward end of movie.
                    Also video loops, there's a green dashed progress bar which I'd like to delete, no stop, pause, rewind, or end buttons, only volume and play buttons which don't work .

                    See work in progress: http://DStall.com/Moon.php
                    • 7. Re: Flash movie control buttons
                      kglad Adobe Community Professional & MVP
                      by "wanna bet" i was opining that cl's attempt to get you started, wouldn't.
                      • 8. Re: Flash movie control buttons
                        ihong7 Level 1
                        lol =D (totally becoming spam)
                        • 9. Re: Flash movie control buttons
                          clbeech Level 3
                          OMG LMAO!!!! @ kg :)

                          dstx - you didn't say anything about your file playing an actual 'video' file, which is what the FLV component is for, and i assumed that you were talking about playing the main timeline itself. it's my guess that the component is really just currently 'sitting' on top of the other assets in the timeline having no effect, one cannot control the timeline with the FLV component. follow the directions i have given to get you started, i didn't state them for no reason, this is how to go about it.
                          • 10. Re: Flash movie control buttons
                            dstx Level 1
                            I put rewind, stop, play, and end buttons on "Controls" layer with frames extending full length of timeline.
                            With Control layer highlighted, I opened Actions window, clicked on stop button and added actionscript for "stop" per your instruction, then did same for remaining 3 buttons.

                            When I play movie online, rewind button works for video, but sound continues to play on continuous.
                            End button jumps about several hundred frames, not to end of timeline.
                            Neither stop nor play buttons work.

                            Output Window (will kg have last laugh?)

                            **Error** Scene=MoonOfWintertime, layer=Controls, frame=1:Line 1: Wrong number of parameters; gotoAndStop requires between 1 and 2.
                            gotoAndStop(gotoAndStop(gotoAndStop(gotoAndStop(gotoAndStop();

                            **Error** Scene=MoonOfWintertime, layer=Controls, frame=1:Line 2: ')' or ',' expected
                            );

                            **Error** Scene=MoonOfWintertime, layer=Controls, frame=1:Line 1: Statement must appear within on handler
                            gotoAndStop(gotoAndStop(gotoAndStop(gotoAndStop(gotoAndStop();

                            **Error** Scene=MoonOfWintertime, layer=Controls, frame=1:Line 4: Unexpected ')' encountered
                            );

                            Total ActionScript Errors: 4 Reported Errors: 4
                            • 11. Re: Flash movie control buttons
                              dstx Level 1
                              Per your instructions, here is the code I entered in the Actions Panel for the Control layer
                              Each button was given corresponding instance name:

                              RewindButton.onPress = function() {
                              gotoAndStop(1);
                              }
                              StopButton.onPress = function() {
                              stop();
                              }
                              PlayButton.onPress = function() {
                              play();
                              }
                              EndButton.onPress = function() {
                              gotoAndStop(_totalFrames);
                              }
                              • 12. Re: Flash movie control buttons
                                kglad Adobe Community Professional & MVP
                                no, i'm not laughing now. you look like you're moving quickly in the correct direction.

                                but your basic setup is unclear. you have a main timeline with what on it? an embedded video? timeline animation? sound attached to frames? something else? some combination of the above?
                                • 13. Re: Flash movie control buttons
                                  dstx Level 1
                                  I have a main timeline animation with sound, about 25-30 layers of bitmap and png images that are also converted to symbols for fade in/fade out, overlay and animation.

                                  I just recently attached sound to the "Controls" layer on which I placed all the buttons, in order to try to produce a control panel in the .swf export file for rewind, play, stop, pause and go_to_end of movie.
                                  • 14. Re: Flash movie control buttons
                                    kglad Adobe Community Professional & MVP
                                    in the properties panel check/change your sound to streaming. retest your controls.
                                    • 15. Re: Flash movie control buttons
                                      clbeech Level 3
                                      right on kg :)

                                      in reviewing the errors I'm wondering about a few other things as well, the line: gotoAndStop(gotoAndStop ... etc - seems to indicate that there is a code line written somewhere that is incorrect, looks like it might have been a 'paste' typo error kinda thing ... LOL ;) happens to us all at times, but you may want to look for that - AND it seems as thought this error line is has been 'attached' to an object (most likely the related button) because another error states 'must be placed within an on handler' - this indicates that the code is attached to the button - which is what ihong7 suggest was firstly, and that i had said was not a 'best' practice - so i guessing here that there is some 'residual' code left there - see if you can locate that. however that odd thing here is that the error path seems to point at the timeline... hmmm.

                                      also i notice that you a have a 'named' scene in your file, are there additional scene as well? this may be part of the problem with the end button which should navigate to the last frame, and you say is not working. if the last frame your looking to go to is within another scene, you may also need to include the scene within the gotoAndStop call.
                                      • 16. Re: Flash movie control buttons
                                        dstx Level 1
                                        There is only 1 scene.
                                        I had created more to try to manage layers as I have a lot of them, but then realized I should do that with folders withing the 1 scene instead because I wanted sound to play continuously through 1 scene to the next.

                                        I followed kg's instruction and got control buttons to work perfectly,
                                        except file kept repeat playing.

                                        I have Sync menu set to stream as kg says, and menu next to it set to repeat (not loop), with numerical value entered as 0.

                                        I modified button images in Photoshop, imported to library, converted to button symbol, and reaasigned code.
                                        Now control functions won't work again.

                                        Yes, I selected button and Control layer both when entering code, so I went back and selected each button and deleted code from association with it, so code is now only associated with Control layer where buttons are located.

                                        Now, no errors in Output, but controls still don't work.
                                        • 17. Re: Flash movie control buttons
                                          clbeech Level 3
                                          very good, you're getting there :)
                                          did you assign 'instance names' to the control buttons?
                                          • 18. Re: Flash movie control buttons
                                            dstx Level 1
                                            Found the mistake: failed to enter instance name for buttons so code didn't recognize them when pressed.

                                            Thanks for the help.

                                            A final question:
                                            Is there any way to write code for "pause" function where pressOn1=stops, and pressOn2=play, etc.?
                                            • 19. Re: Flash movie control buttons
                                              kglad Adobe Community Professional & MVP
                                              pause toggle:

                                              • 20. Re: Flash movie control buttons
                                                clbeech Level 3
                                                dstx - you're welcome :)

                                                nice kg - that's an efficient toggle setup!

                                                just for fun, how about :D

                                                pauseBtn.onRelease = function() {
                                                (toggle = (toggle) ? false : true) ? stop() : play();
                                                }
                                                • 21. Re: Flash movie control buttons
                                                  dstx Level 1
                                                  Why does play keep repeating if I have Properties - Sync set to Stream, Repeat 0?


                                                  • 22. Re: Flash movie control buttons
                                                    kglad Adobe Community Professional & MVP
                                                    there shouldn't be any keyframes (except frame 1) in the layer that contains your sound.
                                                    • 23. Re: Flash movie control buttons
                                                      dstx Level 1
                                                      Sound was selected in Properties of Control layer which has frames for full timeline.
                                                      Created new Soundtrack layer, deleted all frames and inserted frame on frame 1 only, then selected sound in Properties.

                                                      Movie doesn't autoplay which is fine.
                                                      However, when I press play button, video plays but I now get no sound at all.
                                                      • 24. Re: Flash movie control buttons
                                                        kglad Adobe Community Professional & MVP
                                                        if you did that correctly you would see a wavy line in the sound layer that extends from frame 1 to the frame where the sound ends. if you see the wavy line, set your sound to stream.
                                                        • 25. Re: Flash movie control buttons
                                                          dstx Level 1
                                                          Length of my timeline was established to correspond to lenght of sound file.

                                                          I reselected sound on Controls (or Actions) layer,
                                                          then added the following to first line of actionscript code:

                                                          // Stops the playhead at Frame 1.
                                                          stop()

                                                          Seems to work fine.
                                                          • 26. Re: Flash movie control buttons
                                                            dstx Level 1
                                                            Length of my timeline was established to correspond to lenght of sound file.

                                                            I reselected sound on Controls (or Actions) layer,
                                                            then added the following to first line of actionscript code:

                                                            // Stops the playhead at Frame 1.
                                                            stop()

                                                            Seems to work fine. Thanks.
                                                            • 27. Re: Flash movie control buttons
                                                              kglad Adobe Community Professional & MVP
                                                              you're welcome.