3 Replies Latest reply on Aug 28, 2007 7:54 AM by kglad

    targetInstanceName ???

    D3
      I've seen script that uses this targetInstanceName and I'm not sure how it works. I'm trying to use the following code but don't understand how or where to reference either a external SWF or a movie clip that is on _parent.

      Can anyone help me with this? Thanks in advance!!

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

      // Public: pMovie
      // Object: File to load
      pMovie = this._filePath;
        • 1. Re: targetInstanceName ???
          kglad Adobe Community Professional & MVP
          what are you trying to accomplish?
          • 2. Re: targetInstanceName ???
            D3 Level 1

            Thanks for the response Kglad,

            Well I been searching for a prebuilt flash movie controller that uses a slider that controls a SWF. Same concept as a regular media player. I only found one, it was written by some guy named Dave Stroy, and it really works great. I'm only have one problem with it. He uses pTarget as a var name and path and also uses pMovie as a file path? I'm not sure what his logic is there. I can put an absolute path in the pTarget to a movie clip on the _root and it works fine except it doesn't automatically play when loaded and that's what I need it to do. So I'm not sure if I'm breaking any code by putting in this absolute path and if I don't I'm not sure how this _targetInstanceName works?

            Here's the entire code:

            /*
            +------------------------------------------------+
            | 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();
            • 3. Re: targetInstanceName ???
              kglad Adobe Community Professional & MVP
              there is no _targetInstanceName in flash. that's a custom property that must be in the code somewhere.

              i built a custom class for a slider that allows a user to control any movieclip property including its _currentframe, as well as, a number of other things for which sliders are used.