7 Replies Latest reply on Oct 7, 2009 3:11 AM by deansawyer

    Getting a button to be visable only after the flv has loaded?

    deansawyer

      Hey Everyone,

      Trying to find a solution to this question, I've found lots of answers on making a button visable after a swf has loaded but not a flv. I am preloading an flv, well 20secs of it, then it starts playing. But I have a 'play' button on the stage and it sits there tempting people to hit it whilst the preloading bar works its magic preloading the flv. I want the button to be visable only after the flv has loaded or at least until it starts to play.
      I am a newbie to coding so please be kind and spell it out to me nice and clearly. :-)


      Thanks.

      (BTW no components were used)


      Here's my code;

      stop();

      /////Btn controls/////
      btnPausePlay.onRelease = function() {
      ns.pause();
      }

      /////preload and play flv///////

      var duration:Number = 0;
      var ratio:Number = 0;
      var idTracking:Number = 0;
      var idLoading:Number = 0;

      var nc:NetConnection = new NetConnection();
      nc.connect(null);
      var ns:NetStream = new NetStream(nc);
      my_video.attachVideo(ns);
      ns.play("presenter.flv");
      //////change this (20) to th amount of seconds you want to laod before playing///
      ns.setBufferTime(15);


      ns.onMetaData = function(evt:Object):Void {
      duration = evt.duration;
      ratio = track._width / duration;
      idTracking = setInterval(updateKnob, 50);
      idLoading = setInterval(updateLoader, 50);
      };

      ns.onStatus = function(evt:Object):Void {
      if (this.time > 0 && this.time >= (duration - 0.5)) {
      gotoAndPlay(2)
      clearInterval(idTracking);
      delete this.onStatus;
      }
      };

      function updateKnob():Void {
      knob._x = track._x + ns.time * ratio;
      }

      knob.onPress = function():Void {
      clearInterval(idTracking);
      ns.pause(true);
      this.onMouseMove = function():Void {
      if (track._xmouse > 0 && track._xmouse < loader._width) {
      this._x = track._x + track._xmouse;
      }
      }
      }
      knob.onRelease = function():Void {
      delete this.onMouseMove;
      ns.seek((this._x - track._x) / ratio);
      ns.pause(false);
      idTracking = setInterval(updateKnob, 50);
      }
      knob.onReleaseOutside = knob.onRelease;

      function updateLoader():Void {
      loader._xscale = ns.bytesLoaded / ns.bytesTotal * 100;
      if (loader._xscale >= 98) {
      loader._xscale = 100;
      clearInterval(idLoading);
      }
      }

      track.onRelease = function():Void {
      if (this._xmouse > 0 && this._xmouse < loader._width) {
      clearInterval(idTracking);
      idTracking = setInterval(updateKnob, 50);
      ns.seek(this._xmouse / ratio);
      }
      }

      //////////////

        • 1. Re: Getting a button to be visable only after the flv has loaded?
          kglad Adobe Community Professional & MVP

          you can use your onStatus method to check when the buffer is full:

           




          stop();

          /////Btn controls/////
          btnPausePlay.onRelease = function() {
          ns.pause();
          }

          /////preload and play flv///////

          var duration:Number = 0;
          var ratio:Number = 0;
          var idTracking:Number = 0;
          var idLoading:Number = 0;

          var nc:NetConnection = new NetConnection();
          nc.connect(null);
          var ns:NetStream = new NetStream(nc);
          my_video.attachVideo(ns);
          ns.play("presenter.flv");
          //////change this (20) to th amount of seconds you want to laod before playing///
          ns.setBufferTime(15);


          ns.onMetaData = function(evt:Object):Void {
          duration = evt.duration;
          ratio = track._width / duration;
          idTracking = setInterval(updateKnob, 50);
          idLoading = setInterval(updateLoader, 50);
          };

          ns.onStatus = function(evt:Object):Void {

          if(evt.code=="NetStream.Buffer.Full"){

          // do whatever with your play button.  your buffer is full

          }

          if (this.time > 0 && this.time >= (duration - 0.5)) {
          gotoAndPlay(2)
          clearInterval(idTracking);
          delete this.onStatus;
          }
          };

          function updateKnob():Void {
          knob._x = track._x + ns.time * ratio;
          }

          knob.onPress = function():Void {
          clearInterval(idTracking);
          ns.pause(true);
          this.onMouseMove = function():Void {
          if (track._xmouse > 0 && track._xmouse < loader._width) {
          this._x = track._x + track._xmouse;
          }
          }
          }
          knob.onRelease = function():Void {
          delete this.onMouseMove;
          ns.seek((this._x - track._x) / ratio);
          ns.pause(false);
          idTracking = setInterval(updateKnob, 50);
          }
          knob.onReleaseOutside = knob.onRelease;

          function updateLoader():Void {
          loader._xscale = ns.bytesLoaded / ns.bytesTotal * 100;
          if (loader._xscale >= 98) {
          loader._xscale = 100;
          clearInterval(idLoading);
          }
          }

          track.onRelease = function():Void {
          if (this._xmouse > 0 && this._xmouse < loader._width) {
          clearInterval(idTracking);
          idTracking = setInterval(updateKnob, 50);
          ns.seek(this._xmouse / ratio);
          }
          }

          //////////////

          1 person found this helpful
          • 2. Re: Getting a button to be visable only after the flv has loaded?
            DraconianDevil

            What I would do, is move the button to the frame that starts playing after preloader does its magic!

             

            i mean, after the preloader decides that it has loaded enough, it might tell the flash to go and play from frame 12.. (suppose) so I put the button on frame 12 so its not available while the preloader is loading..

             

             

            is it this simple, or did I miss something in your requirements?

             

            thank you

            1 person found this helpful
            • 3. Re: Getting a button to be visable only after the flv has loaded?
              deansawyer Level 1

              This sounds like a good solution, I assume that the buffer being full means that the video has at least partially or fully loaded. Can you help one step further; My button actions are below, how do i make this button invisible until the net stream buffer is full- then make it visable?

               

              Thanks.

               

              /////Btn controls/////
              btnPausePlay.onRelease = function() {
              ns.pause();
              }

              • 4. Re: Getting a button to be visable only after the flv has loaded?
                deansawyer Level 1

                Draconian Devil,

                 

                Thanks for the input, it does seem that simple, but its not, well at least to me. I'm a complete newbie to code and so what I have built so far has been sourced from elswhere on the net. From what I understand this code does the following;

                 

                The preloader is loading in external flv data so works slightly differently to swf preloaders, there is code in there that says once its preloaded, play the flv then once it's played, go to the next frame. I think the preloader actually hides behind the flv once its loaded, but thats fine.

                 

                Basically what i'm saying is I have no idea how to move the timeline along one frame once the flv has loaded and if it did move over would the code to move it aong one more frame once its been played through still work? I may investigate this line of inquiry if the other solution doesn't work out.

                 

                Hold that thought.

                • 5. Re: Getting a button to be visable only after the flv has loaded?
                  deansawyer Level 1

                  I've just googled this, and come up with the following, I'm hoping that this code makes my button (btnPausePlay) visible when the net stream buffer is full.

                   

                      if(evt.code=="NetStream.Buffer.Full"){
                          btnPausePlay._visible = true;
                  // do whatever with your play button.  your buffer is full
                  }

                  • 6. Re: Getting a button to be visable only after the flv has loaded?
                    kglad Adobe Community Professional & MVP

                    that's correct.

                     

                    don't forget to initialize it's _visible property to false.

                    • 7. Re: Getting a button to be visable only after the flv has loaded?
                      deansawyer Level 1

                      That's great thanks, I found out the code from another forum too, using the same code you have given me; for attention of anyone who reads this and is after the soution its here:

                       

                      //first hide your button
                      btnPausePlay._visible = false;

                      ns.onStatus = function(evt:Object):Void
                      {
                           //Playback has stopped - movie has ended
                           if (evt.code == "NetStream.Play.Stop")
                              {
                                gotoAndPlay(2);
                                clearInterval(idTracking);
                           }
                           
                           //The buffer is full and the stream will begin playing.
                           if (evt.code == "NetStream.Buffer.Full")
                             {
                                //show your play button here
                                     btnPausePlay._visible = true;
                           }
                           
                      };