0 Replies Latest reply on Aug 31, 2007 6:43 AM by D3

    Great movie controller but one thing I need help figuring out.

    D3 Level 1
      This code was created by Dave Stroy. The slider controls any movie clip or external SWF. There's just one thing I need it to do that I can't figure out. Currently, the movie plays until it ends and then it rewinds back to it's starting point. I need it to stop at the end of the movie, keeping the play head/ slider at the end of the progress bar. I've tried a bunch of options like puting a stop at the end of the movie clip, which does stop the controller the way I want it to but then it doesn't work properly when I try to play the movie clip after that?

      Here's the code and you'll have to create a simple tween on the _root to use the slider.

      /*
      +------------------------------------------------+
      | Movie Controller Component |
      | by davestroy March 27, 2003 |
      | Control external Squeezed swf |
      | stay cool! davestroy@davstroy.net |
      +------------------------------------------------+
      */

      // Private: #initclip
      // Global definitions for all instances on stage
      #initclip
      for (clip in this){
      this.clip.useHandCursor = false;
      }
      #endinitclip


      /* PUBLIC PROPERTIES */

      // Public: pTarget
      // Object: Reference to target movieclip
      pTarget = this._parent[this._targetInstanceName];

      // Public: pMovie
      // Object: File to load
      pMovie = this._filePath;

      // Public: pMovie
      // Object: Width of progress bar
      pProgressWidth = this._progressWidth;

      frame.top._width = pProgressWidth;
      frame.bot._width = pProgressWidth;
      frame.right._x = pProgressWidth;

      /* PRIVATE PROPERTIES */

      // Private: pPlaying
      // Bool:
      pPlaying = false;

      // Private: pDragging
      // Bool:
      pDragging = false;

      // Private: pPercent
      // Int: Percent loaded
      pPercent = 0;

      // Private: pSliderX
      // Int: Initial x pos of slider
      pSliderX = slider._x;


      /**
      * PUBLIC MEMBER FUNCTIONS
      *
      * Public: Most common functions to control
      * target movie state (play, stop, load, etc)
      *
      */

      this.Reset = function(){
      pPercent = 0;
      pPlaying = false;
      pTarget.unloadMovie();
      }

      this.Play = function(){
      pTarget.play();
      pPlaying = true;
      }

      this.Load = function(aMovie){
      if (aMovie != null){
      pMovie = aMovie;
      }
      pTarget.loadMovie(pMovie);
      pPlaying = true;
      setClipState(cPlay);
      }

      this.Stop = function(){
      pTarget.stop();
      pPlaying = false;
      }

      this.Rewind = function(){
      pTarget.gotoAndStop(1);
      pPlaying = false;
      slider._x = pSliderX;
      }


      /**
      * PRIVATE MEMBER FUNCTIONS
      *
      * Private: Update elements depending on
      * target movies current state.
      *
      */

      this.onEnterFrame = function(){
      if(pPercent < 100 ){
      Loading();
      }
      if(pDragging){
      Dragging();
      }else if (pPlaying){
      Playing();
      }
      }

      this.Loading = function(){
      if (pTarget.getBytesTotal() == 0) return;
      //pPercent = Math.round((pTarget.getBytesLoaded() / pTarget.getBytesTotal()) * 100);
      //progress._xscale = pPercent;
      pPercent = pTarget.getBytesLoaded() / pTarget.getBytesTotal();
      progress._width = Math.round(pPercent * frame.top._width);
      }

      this.Playing = function(){
      var dif = pTarget._currentframe / pTarget._totalframes;
      var curpos = dif * (progress._width - progress.slider._width);
      slider._x = Math.round(curpos);
      //Timecode();
      }

      this.Timecode = function(){
      var sec = Math.round(pTarget._currentframe / 12);
      var min = int(sec/60);
      sec -= min * 60;
      if(min < 10) min = "0" + min;
      if(sec < 10) sec = "0" + sec;
      timecode.text = min+":"+sec;
      }

      this.Dragging = function(){
      var dif = slider._x / progress._width;
      var curframe = Math.round(dif * pTarget._totalframes);
      pTarget.gotoAndStop(curframe);
      }

      /**
      * SLIDER FUNCTIONS
      *
      * Private: Control target movie from draging the slider
      * Overrides Play, Stop, Rewind and Pause functions
      *
      */

      this.slider.onPress = function(){
      pDragging = true;
      startDrag(this,false,0,this._y,this._parent._width-this._width,this._y);
      }

      this.slider.onRelease = function(){
      pDragging = false;
      stopDrag();
      if(pPlaying) this._parent.Play();
      }

      this.slider.onReleaseOutside = function(){
      pDragging = false;
      stopDrag();
      if(pPlaying) this._parent.Play();
      }

      /**
      * PROGRESS FUNCTIONS
      *
      * Private: Control target movie from pressing the progress bar
      * Overrides Play, Stop, Rewind and Pause functions
      *
      */

      this.progress.onPress = function(){

      var curframe = Math.round(((_xmouse - progress._x) / progress._width) * pTarget._totalframes);
      if(pPlaying){
      pTarget.gotoAndPlay(curframe);
      }else{
      pTarget.gotoAndStop(curframe);
      Playing();
      }
      }


      /**
      * PLAY, STOP, PAUSE, REWIND
      *
      * Private: Control target movie
      * Set state of buttons and command target movie
      *
      */

      this.setClipState = function(obj){
      if(pCurbut == obj) return;
      obj.gotoAndStop("On");
      pCurbut.gotoAndStop("Off");
      pCurbut = obj;
      }

      this.cPlay.onRelease = function(){
      setClipState(this);
      this._parent.Play();
      }

      this.cPause.onRelease = function(){
      setClipState(this);
      this._parent.Stop();
      }

      this.cStop.onRelease = function(){
      setClipState(this);
      this._parent.Rewind();
      }

      if(this.pMovie != ""){
      this.Load();
      }

      stop();