4 Replies Latest reply on Jun 18, 2007 2:07 AM by Greg Dove

    extending and MovieClip?

      This is really aggravating me. I come from a OOP background so Java and others are natural to me but ActionScript 2 is really really unintuitive even thought it tries really hard to be a object oriented language. So sorry if some of my question comes off as rant/frustration.

      I'm trying to extend the MovieClip class but it seems "class Test extends MovieClip" isn't actually a MovieClip!!! wtf

      [code]
      class Test extends MovieClip {
      function Test(){
      trace("constructor called");
      lineStyle(5, 0xFF00FF, 100);
      moveTo(200, 200);
      lineTo(300, 300);
      lineTo(100, 300);
      lineTo(200, 200);
      }
      }



      On frame 1:

      import Test;
      stop();
      var myMc = new Test();

      [/code]
      It outputs constructor called, but it doesn't draw anything and in true Actionscript fashion, outputs no errors or warnings whatsoever.

      It seems that a class that extends a MovieClip isn't actually a MovieClip. So much for that "is-a" relationship that its supposed to have. or i guess it gives you access to the MovieClip functions, but theres no point because theres no MovieClip on the stage... Sure I suppose I could create an empty movie clip in the constructor and put things in there, but then whats the point of extending MovieClip? If Test really is a MovieClip it should be able to draw on itself.

      What am I not getting???
        • 1. Re: extending and MovieClip?
          MurMeeKeer Level 1
          Hi,

          MovieClip itself is a built-in class. You're extending that class, that's all! For your purpose,

          1. Draw a movie clip on the stage.
          2. Open the library panel and right click on the movie clip you just created, and select 'linkage' from the list.
          3. From the dialog box that appears, select the 'Export for ActionScript' check box.
          4. In the AS 2.0 class field, type 'Test'. Click OK and close.

          Now, test the movie and you will realize that how the original movie clip class has been extended.

          Apart from this, you can create custom classes also.
          1 person found this helpful
          • 2. Re: extending and MovieClip?
            Yeah, you can link a class with a MovieClip symbol, but then you have to use the attachMovie() function which is outdated actionscript 1.0 style. Additionally you have to have a blank MovieClip symbol defined in the library for each class that extends MovieClip. If you make children classes, you have to create new symbols for those, etc, etc. If a class extends MovieClip, instantiating it should create a MovieClip. That seems like the natural thing to do... But instead you have to use these funky attachMovie or createEmptyMovieClip functions. Is this fixed in AS 3.0?
            • 3. extending and MovieClip?
              MurMeeKeer Level 1
              Good analysis but I'm a novice in AS 3. Anybody can answer this? I'm also waiting for some nice replies.
              1 person found this helpful
              • 4. Re: extending and MovieClip?
                Greg Dove Level 4
                Yes, I believe its more like you're used to in as3.

                So in as2 extending a MovieClip is not "as it should be". But its not too difficult to get used to. If you're just starting with actionscript coming from another OOP language you may want to start with as3.

                If you're doing it in as2 then cast the return type of attachMovie to your class.

                var mynewThing:Thing = attachMovie("thingClip", "firstThing", nextdepth)
                There are some 'tricks' to avoid using a library symbol:

                "an empty movie clip is automatically created for your class in your library with the linkage id __Packages.[full class name]. So you could just use that without defining any symbols yourself."
                -source: http://board.flashkit.com/board/showthread.php?t=615810

                example: