4 Replies Latest reply on Sep 1, 2007 5:17 PM by TimSymons

    How to access children movie clips from a parent class

    petersendidit2
      So say I have a class named Thing that extends MovieClip.
      Then I have a class named Box that extends Thing.
      I also have a class name Circle that extends Thing.

      I then create 2 movie clips on in my FLA. One uses the Box class and one uses the Circle class.
      Both movie clips have a child movie clip named dot.

      How do I access the dot MovieClip from a function in Thing?

      The following code throws a error:
      1119: Access of possibly undefined property dot through a reference with static type Thing.

      How do I accomplish this correctly?

        • 1. Re: How to access children movie clips from a parent class
          SymTsb Level 2
          Looking at your code, I cannot fathom what it is that you are trying to do....

          Your Thing class isn't going to have access to dot if it exists in your two mcs inside your main fla. not unless you use MovieClip(root).mc1.dot.y = 30; dot is not a member of the Thing class and therefore Thing cannot access it. At least not the way you are wanting. If you setup each of your mcs to be exported for AS and set their Class name as Box and Circle, then instantiating them would give you access to their dot member but not in the way you might think.

          // Instantiate Circle MC
          var mycircle:Circle = new Circle();
          mycircle.dot.y = 30;

          This would be a legal call. Parent classes do not inherit anything from their children. Their children inherit access to their methods. I wish I better understood what it was you were trying to do because then I might be able to help you get it working but based on what you have here I'd have to say you have things turned a bit inside out.
          • 2. Re: How to access children movie clips from a parent class
            Cathie101
            If you wished to extend this code for the movie clip to have an onPress event, how is this done?
            If you create a number of objects dynamically of one of the children classes, in the actions on the stage, (still working in AS2), how do you get the object to respond to an onPress event?
            Eg can you implement a listenerAction like in java.
            The code below has the onPress event working but not it doesn't know which object has pressed it.
            • 3. Re: How to access children movie clips from a parent class
              SymTsb Level 2
              I wish I could tell you more. In AS2, you had to code each button independently. It did not have an Event Dispatch methodology like AS3 has. AS2 does have listeners but they are no where near as powerful as they are in AS3. All I can suggest is to look up listeners in the AS2 help and based on what you are doing, go from there. I personally prefer AS3s method of doing things since they are much more OOP oriented and a great deal more flexible than AS2.
              • 4. Re: How to access children movie clips from a parent class
                TimSymons Level 1
                In AS3 you could use the getChildAt or getChildByName method to reach the "dot" movieclip of either "Box" or "Circle".

                Assume we are in the Thing class (this scopes to Thing).

                this.getChildByName("Circle").dot;



                Tim