2 Replies Latest reply on Jun 28, 2006 5:11 AM by Newsgroup_User

    Creating you own class

    Tolk Level 1
      Iv'e created an empty movieclip in my main fla. and assigned it's AS 2.0 Class to a custom class i created in an external as file.
      I want my custom class at some stage to draw an emptyMovieClip into this containing movieClip on the main fla.
      I tried using, in the class draw procedure:

      this.createEmptyMovieClip(all the gubbins in here);

      But it doesnt work, i tried changing the "this" for "_root" and this works but i'm not sure where its drawing the movieClip too, surely that would be drawing it onto the root stage and not into the movieClip container.
      Another methods i did to get around this was in the draw method of the class pass in a movieClip target i.e. would use:

      containerMC.drawChart(containerMC);

      This works fine but it seems a little stupid to me, is there not some way to reference the containerMC in the class definition (given containerMC wont be a constant name, i.e. depends on instance name).

      Anyway hope that makes sense, thanks for any help you can offer.
        • 1. Re: Creating you own class
          Level 7
          Hi!

          Try to have your class extend MovieClip, so for example:

          class MyClass extends MovieClip {
          ...
          }

          /Jensen/

          "Tolk" <webforumsuser@macromedia.com> wrote in message
          news:e7tikb$g5o$1@forums.macromedia.com...
          > Iv'e created an empty movieclip in my main fla. and assigned it's AS 2.0
          > Class
          > to a custom class i created in an external as file.
          > I want my custom class at some stage to draw an emptyMovieClip into this
          > containing movieClip on the main fla.
          > I tried using, in the class draw procedure:
          >
          > this.createEmptyMovieClip(all the gubbins in here);
          >
          > But it doesnt work, i tried changing the "this" for "_root" and this
          > works
          > but i'm not sure where its drawing the movieClip too, surely that would be
          > drawing it onto the root stage and not into the movieClip container.
          > Another methods i did to get around this was in the draw method of the
          > class
          > pass in a movieClip target i.e. would use:
          >
          > containerMC.drawChart(containerMC);
          >
          > This works fine but it seems a little stupid to me, is there not some way
          > to
          > reference the containerMC in the class definition (given containerMC wont
          > be a
          > constant name, i.e. depends on instance name).
          >
          > Anyway hope that makes sense, thanks for any help you can offer.
          >


          • 2. Re: Creating you own class
            Level 7
            Tolk,

            >> Iv'e created an empty movieclip in my main fla. and
            >> assigned it's AS 2.0 Class to a custom class i created
            >> in an external as file.

            As Jensen mentioned, your class will have to extend MovieClip for this
            to work.

            class MyCustomClass extends MovieClip {
            ...
            }

            If you don't do that, your class is just a class; in other words, it just
            instantiates an object (whatever object you define in that class). If it
            extends MovieClip, then it *is* a movie clip -- plus whatever else you
            define.

            >> I want my custom class at some stage to draw an
            >> emptyMovieClip into this containing movieClip on
            >> the main fla. I tried using, in the class draw procedure:
            >>
            >> this.createEmptyMovieClip(all the gubbins in here);

            That would only work if the "this" reference resolves to a movie clip.
            Since your class doesn't extend MovieClip, none of the MovieClip features
            are available to it, including createEmptyMovieClip(). If you don't extend,
            you'll have to use composition here -- meaning, declare a MovieClip property
            in your class and use *that* as your movie clip reference.

            >> i tried changing the "this" for "_root" and this works

            Sure thing. _root always points to the main timeline of the currently
            active level. The main timeline is, effectively, a movie clip.

            >> but i'm not sure where its drawing the movieClip
            >> too, surely that would be drawing it onto the root
            >> stage and not into the movieClip container.

            Bingo.

            >> Another methods i did to get around this was in the
            >> draw method of the class pass in a movieClip
            >> target i.e. would use:
            >>
            >> containerMC.drawChart(containerMC);

            That's a thought, sure. Otherwise, how would an instance of your class
            know where this container clip was? Attaching it to the movie clip isn't
            enough. Seems like it should be -- I can see that -- but that attachment
            business is only for classes that extend MovieClip (as far as I know).


            David
            stiller (at) quip (dot) net
            Dev essays: http://www.quip.net/blog/
            "Luck is the residue of good design."