2 Replies Latest reply on Apr 11, 2007 2:24 PM by Peter Lorent

    AS 2.0 Question

    ChrisFlynn Level 1
      Hi all

      I'm a bit of a newb when it comes to AS 2.0 and writing classes. But I have a question about inheritance.

      Right now I have 3 classes, Thing, Gravity, and Ball. This is how they're set up.

      Thing.as

      class Thing extends MovieClip {
      //Code
      }

      Gravity.as

      class Gravity extends Thing{
      //Code
      }

      Ball.as

      class Ball extends Thing {
      //Code
      }

      So essentially, both Ball and Gravity classes inherit the Thing class. This is OK to do right?

      So far, I haven't got any errors, but I haven't done much with these either. I was hoping to get some advance before I continue down this road.

      The idea is that my "Ball" happens to be a "Thing", and all "Things" happen to be effected by "Gravity", at least on this planet. Then to build upon this, I'd create different kind of balls, like bowling balls, basketballs, tennis balls, and show how each react different when they're dropped.

      Am I going about this the right way?

      I have my doubts about this whole process, so if someone can lead me in the right drection, that would be great.

      Thanks
      Chris
        • 1. Re: AS 2.0 Question
          Rothrock Level 5
          Well yes and no. Many different classes can extend a super class. So that shouldn't be a problem. But do you really need to extend Thing for Gravity?

          Is Gravity a Thing? Will Gravity need all the methods and properties of the Thing class?

          Seems more likely that you need to include by composition an instance of Gravity in your Thing class. Maybe as a Static property or method? Or do all instances of Thing need their own gravity? Now we are beyond me!