3 Replies Latest reply on Dec 7, 2007 2:54 AM by chrisatflash

    basic OOP question.

    chrisatflash Level 1
      Hello, can anyone explain why the value keeps returning a undefined value?
      this.speedX and this.speedY are undefined.

      in the source file i used to instanciate the class:

      var test:csmove = new csmove(circle, 2,2);

        • 1. Re: basic OOP question.
          Level 7
          if you are using AS2 when you set the onEnterFrame to upsdatepositie
          the scope of that function doesn't belong to your class. to ensure
          this you must use Delegate.create

          ...
          import mx.utils.Delegate;
          ...

          function movenow() {
          this.targetMC.onEnterFrame = Delegate.create(this,
          this.upddatepositie);
          }

          and if you want that the targetMC keep on moving inside updatepositie
          you should have

          targetMC._x += this.speedX;
          targetMC._y += this.speedY;

          hope this is usefull

          • 2. Re: basic OOP question.
            Level 7
            You can use delegate as Roberto suggested, or you can simply put your speed
            variables within your target clip:

            function csmove(targetClip:MovieClip, X, Y) {
            this.targetMC = targetClip;
            this.targetMC.speedX = X;
            this.targetMC.speedY = Y;
            }

            You don't need to change anything else. Now when you say this.speedX inside
            your updaepositie() you will be referring to the speedX property of the
            clip. Note also, I changed the function param above to targetClip - I just
            don't like using same named vars like that.

            --
            Dave -
            Head Developer
            http://www.blurredistinction.com
            Adobe Community Expert
            http://www.adobe.com/communities/experts/


            • 3. Re: basic OOP question.
              chrisatflash Level 1
              Thanks, both methods worked great!

              The Delegate class was new to me.
              The trick to assign a value to a movieclip works also very well.