12 Replies Latest reply on May 25, 2007 1:21 PM by kglad

    extending Sprite?

    hciguy Level 1
      Just a quick, basic question. Every example I see of classes in this OReilly book I have been looking over extends Sprite. Why would they all extend Sprite? I don't see the reaosn or value. They are not overriding any methods of it...

      Thanks in advance.
        • 1. Re: extending Sprite?
          Rothrock Level 5
          Why not extend sprite. My understanding is that the point of extending is inheritance, not so much with the overriding.

          Are you putting these things on the stage? Moving them around? Clicking on them and such? If so, then Sprite gets most of the useful things like that from its parent classes. But they don't seem as natural of a thing to extend.

          I'm new to all of this, but it seems that Sprite really is the replacement for what used to be dynamically created MovieClips. If you don't have a timeline you don't need the MovieClip overhead and Sprite is the next choice up the chain.
          • 2. Re: extending Sprite?
            hciguy Level 1
            The example was just a basic class reading and parsing XML....
            • 3. Re: extending Sprite?
              kglad Adobe Community Professional & MVP
              look at your class and check what functionality it needs. then check the most basic class that has most of that functionality and extend that to add the additional features you want in your custom class.

              for example, the author of your xml read/parse class may have wanted to use the interactiveobject class to respond to user input and wanted something in the displayobject class to add to the display list so it would appear on-screen. the sprite class is the most basic class that extends both those classes and would be a reasonable starting point for your class.

              on the other hand, if your xml read/parse class does not need to respond to user input and does not need to be in the display list it may only need to extend the URLLoader class.
              • 4. Re: extending Sprite?
                hciguy Level 1
                Why do I need to extend a class at all? Can't I just make my own class and not worry about extending?

                Is it just because I want access to that class? Why?

                Does extending allow me to access private methods and properties in the super class?

                Thanks for helping me understand.
                • 5. Re: extending Sprite?
                  kglad Adobe Community Professional & MVP
                  you don't have to extend any class. you can create your own class.

                  however, if you have to duplicate another existing classes methods and properties that's less efficient than extending the existing class.
                  • 6. Re: extending Sprite?
                    kglad Adobe Community Professional & MVP
                    you don't have to extend any class. you can create your own class.

                    however, if you have to duplicate another existing classes methods and properties that's less efficient than extending the existing class.
                    • 7. Re: extending Sprite?
                      hciguy Level 1
                      If or when I extend an existing class, do I get access to private methods and properties of that class? Is it basically that I get to use that class is if my class is a part of it then?

                      Still learning OOP in AS 3.0. I knew it roughly in AS 2.0 but obviously it is more developed now...

                      Thanks!
                      • 8. Re: extending Sprite?
                        Level 7
                        Chances are the book was designed in mind for those not using the Flash IDE.
                        If you are creating an ActionScript only project without Flash (using Flex
                        Builder or MXMLC) then you have to start with a class that extends Sprite or
                        some subclass of Sprite. This sprite class then becomes the "main timeline"
                        instance used as the SWF movie in the Flash player. (This is also
                        comparable to the document class option in Flash - if you make a class for
                        the document class, it will have to extend at least Sprite since that is the
                        requirement for "SWF document" instances)

                        "hciguy" <webforumsuser@macromedia.com> wrote in message
                        news:f36v6f$cej$1@forums.macromedia.com...
                        > Just a quick, basic question. Every example I see of classes in this
                        > OReilly
                        > book I have been looking over extends Sprite. Why would they all extend
                        > Sprite?
                        > I don't see the reaosn or value. They are not overriding any methods of
                        > it...
                        >
                        > Thanks in advance.
                        >


                        • 9. Re: extending Sprite?
                          hciguy Level 1
                          Oh okay. That makes sense since they often speaks as if you're using Flex 2.0 or something. I'm just using good ole Flash IDE.

                          Thanks so much! The world is a clearer place to be now...
                          • 10. Re: extending Sprite?
                            kglad Adobe Community Professional & MVP
                            extending a class does not give access to private functions and private variables. they are available only in that class.

                            protected functions and variables are available in the class in which they originate and subclasses.

                            internal functions and variables are available to all classes in the same package.

                            • 11. Re: extending Sprite?
                              hciguy Level 1
                              Thanks kglad. You rock. :)
                              • 12. Re: extending Sprite?
                                kglad Adobe Community Professional & MVP
                                you're welcome.