3 Replies Latest reply on Apr 4, 2007 4:01 PM by DZ-015

    any way to for a class instance to ask what its instance name is?

    DZ-015
      Hey. I have a class which needs to create a movie clip on the stage. Since each instance of the class will only ever have 1 movie clip on the stage at a time, it seems reasonable that I have the instance create a movie clip with its own name, prefixed with "mc_" or something of the sort.

      Here's where I don't know quite what to do... How do I get at this information? For instance, when you a dealing with an XMLNode, you can simply use...

      the_answer = xmlNodeInstance.nodeName;

      ...I know the analogy fails, but hopefully you know what I'm looking for.

      Thanks!
        • 1. Re: any way to for a class instance to ask what its instance name is?
          kglad Adobe Community Professional & MVP
          movieclips have a _name property AFTER they're instantiated.
          • 2. Re: any way to for a class instance to ask what its instance name is?
            DZ-015 Level 1
            hu....

            and when you create your movie clip, (assuming you don't just build it at authoring time) you specify an instance id through the createEmptyMovieClip function....

            taking a cue from this, I'm guessing that my answer is to change the structure of what I'm doing a little... instantiate my object with an instance name as a parameter given to the Class Constructor... that way the class can have it's own name on file.

            I guess my only concern there is how do I keep the "name" variable from being just completely arbitrary...?

            I guess I'm getting away from application (becaust I don't know when I'd do this...) and into theory.... but for instance, let's say I create my class like this:

            var instanceReference:mySuperCoolClass = new mySuperCoolClass("instanceName");

            So. I have my class instance... ideally, the class would exist on the stage as "instanceName", with "instanceReference" being another way to reference the instance. That would be ideal... but how do I make that happen? Because in the scenario of what I've just done, I see the class instance existing on the stage as "instanceReference", and I've just passed it a fun, but meaningless bit of data called "instanceName"...

            I suppose I could have the class go back to "_parent" and create it's own object.... but here again I'm getting into territory that feels a lot like i have no idea what I'm doing... haha!

            I guess I have enough info to get back to coding for now... But I'm deffinately open to more tips... I feel like I'm still missing how a lot of this works.

            (I'm at that awkward place where I can easily explain what OOP is, but I'm far from experienced in how to implement it... I've only written about half a dozen classes so far... so I still have a lot to learn. Thanks for your patience, all of you!)
            • 3. Re: any way to for a class instance to ask what its instance name is?
              DZ-015 Level 1
              ...another thought... maybe what I need to do is make my class an extension of the MovieClip class...?