11 Replies Latest reply on Apr 16, 2007 7:44 AM by kglad

    OOP problem.

    erokCom
      Hello friends,

      So, I am trying to learn how to write classes to make my life easier in the long run.... I am extending movieClip and using Tweener inside my new class.. Here is what I have:

      import caurina.transitions.Tweener;


      //@ author eric shoemaker
      /////////////////////////////////////////////////////
      ////////////////////////////////////////////////////

      class Mover extends MovieClip {

      public static var Instance:Mover;

      //vars:
      private var targetMC:MovieClip;
      private var xPos:Number;
      private var yPos:Number;

      //constructor:
      function Mover() {
      Instance = this;
      trace("The constructor was called");

      this.targetMC = targetMC;
      this.yPos = yPos;

      }

      function startMoving(targetMC:MovieClip,yPos:Number) {
      Tweener.addTween(targetMC, {_y:yPos, time:2});
      trace("startMoving was called");



      }

      }





      Now, in my FLA I am calling it like:




      var myMover:Mover = new Mover();

      //
      Mover.startMoving(circle_mc, 400);



      I am getting this error:

      **Error** Scene=Scene 1, layer=as, frame=1:Line 9: The property being referenced does not have the static attribute.
      Mover.startMoving(circle_mc, 400);

      Total ActionScript Errors: 1 Reported Errors: 1



      What does this mean?

      I had it working before, but only if I pass things to the constructor. That looked like:


      import caurina.transitions.Tweener;


      //@ author eric shoemaker


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

      class Mover extends MovieClip {

      public static var Instance:Mover;

      //vars:
      private var targetMC:MovieClip;
      private var xPos:Number;
      private var yPos:Number;

      //constructor:
      function Mover(targetMC:MovieClip,yPos:Number) {
      Instance = this;

      //What are we passing into the class? This part has to be defined!
      this.targetMC = targetMC;
      this.yPos = yPos;
      }

      private function updatePosition() {
      Tweener.addTween(targetMC, {_y:yPos, time:3});

      }


      public static function startMoving() {
      Instance.updatePosition();
      }

      }

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



      Can someone help me in the right direction? If you respond back, can you please post your code so I can see where I made the mistake?

      Thanks so much!!!
        • 1. Re: OOP problem.
          kglad Adobe Community Professional & MVP
          Instance are your Mover instances and you really should make it a private. targetMC and yPos are going to be undefined in your constructor function so that code does nothing. and your startMoving method should act upon one of the Mover class:

          • 2. Re: OOP problem.
            injpix Level 3
            For this error;

            **Error** Scene=Scene 1, layer=as, frame=1:Line 9: The property being referenced does not have the static attribute.
            Mover.startMoving(circle_mc, 400);

            …you would want to use your Mover’s instance name that you created, which is ‘myMover’. So it would be like this;

            myMover.startMoving(circle_mc, 400);


            But it looks like that there are more errors and problems that you need to resolve. Goodluck.
            • 3. Re: OOP problem.
              erokCom Level 1
              Hello,

              Thank you SOOOO much!

              Let me look over this code and I will get back to you ASAP!
              • 4. OOP problem.
                erokCom Level 1
                THANK YOU!!!!!!


                Alright, here is what seems to work:

                • 5. Re: OOP problem.
                  erokCom Level 1
                  Sorry, I think that got pasted in twice!
                  • 6. Re: OOP problem.
                    erokCom Level 1
                    Correction.. This works:
                    • 7. Re: OOP problem.
                      injpix Level 3
                      The following code in your fla;
                      startMoving(circle_mc, 400);

                      …has 2 arguments, “circle_mc” and 400. However in your class startMoving() only has one parameter. You need choose one or the other. And I am thinking it would be best to have 2 arguments like you have.


                      And to explain this;
                      circle_mc.startMoving(400); // assumgin circle_mc is from the Mover class <-----THIS DOES NOT WORK

                      circle_mc is a movieclip that is on stage. It does not know a startMoving method. So it fails silently. One way circle_mc can inherit startMoving method is to have the symbol in the library connected to the Mover class. From what you shown us, you are creating an instance on stage, which is different and will not work for this example. If you want to reuse this method for different symbols (Not different movieclips) then I would suggest creating an instance like you are doing.
                      • 8. Re: OOP problem.
                        kglad Adobe Community Professional & MVP
                        circle_mc.startMoving(400);

                        will work and is the correct syntax IF circle_mc were from the Mover class.

                        because it doesn't work for the op you can conclude that it's not in the Mover class. my guess is the op doesn't know how to create movieclips that are class members and that's where he needs help.

                        erok, right click on a library movieclip, click properties, tick export for actionscript and in the as 2.0 class box type:

                        Mover

                        then click ok.

                        now, retest using the code i gave.
                        • 9. Re: OOP problem.
                          erokCom Level 1
                          Thank you! Let me check it out. :)
                          • 10. Re: OOP problem.
                            erokCom Level 1
                            Thank you! Let me check it out. :)
                            • 11. Re: OOP problem.
                              kglad Adobe Community Professional & MVP
                              you're welcome.