3 Replies Latest reply on Mar 21, 2007 11:20 AM by Newsgroup_User

    Play/pause button actionscript

    Swarfega
      Hi guys,

      I have an embedded video in my application and was just wondering what I would say in an if else statement if I am trying to get a button to perform both play and pause functions. Please include all code, even on the release part. Ta
        • 1. Re: Play/pause button actionscript
          Level 7
          Swarfega,

          > I have an embedded video in my application and was just
          > wondering what I would say in an if else statement if I am
          > trying to get a button to perform both play and pause
          > functions.

          Embedded video in what way? Is this video laid into the timeline of a
          movie clip, for example, or are you using the FLVPlayback Component (or some
          other approach)?

          > Please include all code, even on the release part. Ta

          There are many approaches to playing video in Flash, so to save me some
          time typing, give me an idea how your video is being shown. ;)


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: Play/pause button actionscript
            Swarfega Level 1
            I have embedded it using the following script:

            var nc:NetConnection = new NetConnection();
            nc.connect(null);
            var ns:NetStream = new NetStream(nc);
            myVideo.attachVideo(ns);
            ns.play("Clonmel.flv");
            ns.seek(0);
            ns.pause();

            This goes into a container box which has an instance name. The video is shown on the screen and it plays hen you hit the play button, which currently has the following script:

            on (release){
            ns.play("Clonmel.flv");
            }

            I hope this sufficient enough information for you.
            • 3. Re: Play/pause button actionscript
              Level 7
              Swarfega,

              > I have embedded it using the following script:

              Gotcha.

              > var nc:NetConnection = new NetConnection();
              > nc.connect(null);
              > var ns:NetStream = new NetStream(nc);
              > myVideo.attachVideo(ns);

              Up to this point, you're getting the various objects ready, then ...

              > ns.play("Clonmel.flv");
              > ns.seek(0);
              > ns.pause();

              There your loading a file, then immediately returning it to the
              beginning and pausing. So far, so good.

              > This goes into a container box which has an instance name.
              > The video is shown on the screen and it plays hen you hit
              > the play button, which currently has the following script:
              >
              > on (release){
              > ns.play("Clonmel.flv");
              > }

              Sure thing. As an aside, I recommend that you go with a more modern
              approach to coding up your button. There's nothing invalid or fundamentally
              wrong with the approach you used -- the on() function -- but it's been
              possible since Flash MX (aka 6) to handle button events in a similar way to
              how your accessing other object properties and methods. Just like your
              NetConnection instance has an instance name nc, for example, you can give
              your button an instance name in the Property inspector and assign a function
              to its Button.onRelease event.

              myButton.onRelease = function():Void {
              ns.play("Clonmel.flv");
              }

              See this article for more details, if you're intersted.

              http://www.quip.net/blog/2006/flash/museum-pieces-on-and-onclipevent

              Meanwhile, you don't actually need any if/then logic for this pausing at
              all. :) Check out the NetStream.pause() method entry in the ActionScript
              2.0 Language Reference, for example ... you'll see that this method does two
              things: the first time it's called -- as you've already done -- it pauses
              the NetStream; the second time (when it's paused), it plays it; then pauses
              it, then plays it; etc.

              So all you need is a button that invokes ns.pause().

              > I hope this sufficient enough information for you.

              That helped a lot, actually. :) If the video had been embedded in a
              movie clip timeline, we'd be looking up MovieClip class members instead of
              NetStream class members.


              David Stiller
              Adobe Community Expert
              Dev blog, http://www.quip.net/blog/
              "Luck is the residue of good design."