6 Replies Latest reply on Sep 5, 2006 8:09 PM by kglad

    Proto "what the"

    DazFaz Level 1
      Im trying to apply a prototype funciton to a movieclip and for the life of me I cant get my head around it e.g.

      myFunction.prototype = function(){
      this.onPress = function(){
      trace("working");
      }
      }

      myBoxMovieClipOnTheStage = new myFunction();

      I would expect the "myBoxMovieClipOnTheStage" to now have the function of a button and guess what, nope, not a thing. Can anyone help me on this one.

      Thanks
        • 1. Re: Proto "what the"
          Level 7
          DazFaz,

          > Im trying to apply a prototype funciton to a movieclip and for
          > the life of me I cant get my head around it e.g.

          Prototyped functions are added to all instances of a class, not just
          one.

          > myFunction.prototype = function(){
          > this.onPress = function(){
          > trace("working");
          > }
          > }
          >
          > myBoxMovieClipOnTheStage = new myFunction();

          The prototype property doesn't work that way. Should be:

          MovieClip.prototype.functionName = function(params) {
          // instructions here
          }

          ... which adds a function by the name of functionName (or whatever) to all
          new instances of the MovieClip class from that point forward.


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


          • 2. Re: Proto "what the"
            DazFaz Level 1
            What if I want to only pinpoint a few movieClips to take on the function?
            • 3. Re: Proto "what the"
              kglad Adobe Community Professional & MVP
              when you create a prototype function for a movieclip, you're adding a new method for all movieclips. not all (and not any) movieclips need to use that method.

              for example, mm/adobe created an onDragOut method for movieclips but you may never use it. (i don't think i've ever used it.)
              • 4. Re: Proto "what the"
                DazFaz Level 1
                Surely it would make more sense to be able to apply lets say onRelease function thus:

                myFunction.prototype = function(){
                this.onPress = function(){
                trace("working");
                }
                }

                myBoxMovieClipOnTheStage = new myFunction();

                Then you can pick and choose how and on to which the onRelease function is applied. Rather than the all or nothing approach.
                • 5. Re: Proto "what the"
                  DazFaz Level 1
                  The penny has just dropped. It’s rather a wasteful approach though, applying the function to every movieClip rather than being able to pinpoint a select few.

                  MovieClip.prototype.myNewReleaseFunction = function () {
                  this.onRelease = function(){
                  trace ("working");
                  }
                  };
                  box2.myNewReleaseFunction();

                  Thanks for your help David and kglad (Never thought I would ever say that :¬P)
                  • 6. Re: Proto "what the"
                    kglad Adobe Community Professional & MVP
                    you can restrict methods to only particular movieclips by defining a class and defining a method for that class.