7 Replies Latest reply on May 31, 2007 6:35 AM by kglad

    instance without calling 'new'

    tag_digital Level 1
      I have a class that I use to extend MovieClip so I can add extra data to it. Along with other things I add a textField to the object when Instantiated. (I am including the basic class below) I have different movieClip symbols in the flash libray that I want to call when needed and add this functionallity to. The code works but I get an extra instance before I ever call 'new'. Flash seems to create an instance when run using the linkage properites 'base class' . I have to put my gamePiece class as the base class for the symbol in the library or it doesn't work. I'm really confused what's going on here. When I use in main() gamePiece:GamePiece = new redBall() it works fine (GamePiece is defined as the base class in the linkage properties for redBall. I hope I'm explaining this ok...Can anyone please tell me how I can keep Flash from creating an instance before I even use the class?

      Thanks
        • 1. Re: instance without calling 'new'
          kglad Adobe Community Professional & MVP
          the base class set in your linkage dialog, for movieclips that are members of GamePiece, should be flash.display.MovieClip. is it?
          • 2. Re: instance without calling 'new'
            tag_digital Level 1
            no...its set to GamePiece (that extends MovieClip)...If I set it to flash.display.MovieClip I get an error....

            1067: Implicit coercion of a value of type gameBall1 to an unrelated type GamePiece.

            If I set the base class to GamePiece it works but seems to create an extra one that I never instanciate. Like its being called by itself when flash loads in the class descriptions.
            • 3. Re: instance without calling 'new'
              kglad Adobe Community Professional & MVP
              what's gameBall1?
              • 4. Re: instance without calling 'new'
                tag_digital Level 1
                gameBall1 is the class name of the symbol in the library. (the game piece animation) I have multiple different types but want to define all the functionallity of each one in the GamePiece class. That's why I use the GamePiece Class as the bass class for them. I actualy have everything working pretty much the way I want it to except for that extra instance that shows up when I run it. I don't understand how it gets called when I don't call it.
                • 5. Re: instance without calling 'new'
                  kglad Adobe Community Professional & MVP
                  that's not right and that's why you're having some issues. either live with it because it's not causing much trouble or do it right: if you want the gameBall1 class to extend the GamePiece class set that up in your gameBall1 class.
                  • 6. instance without calling 'new'
                    tag_digital Level 1
                    oh, that is how I was told to do it. So I think I understand, so you can override the class that Flash creates automatically with the name used in the linkage properties for the symbol. So I create a gameBall1 class and extend GamePiece in there. Then for the base class in the linkage properties I use flash.display.MovieClip. Then to create it I would do this...

                    var gp:GamePiece;
                    gp = new gameBall1;

                    Is that correct?

                    Just so I have a better understanding of what was going on under the hood...the problem I was having is that flash was automatically creating an instance of the GamePiece class because it was listed in the symbol linkage properties as the base class?

                    Thanks!
                    • 7. Re: instance without calling 'new'
                      kglad Adobe Community Professional & MVP
                      if your gameBall1 class is supposed to inherit from your GamePiece class, in gameBall1's class definition you should use: