3 Replies Latest reply on Sep 1, 2009 8:09 AM by Paulo Ricca

    Class extends MovieClip but can't call 'addChild'

    Paulo Ricca

      Hi there

      I'm working on a Flash Lite 3.0 application using AS2 and I've created a class that extends MovieClip. The problem is that I'd like to dynamically add Child Movieclips using the addChild method... but it doesn't work, it gives me the following compiler error: "There is no method with the name 'addChild'". But I can call other MovieClip specific methods such as this.getNextHighestDepth()

       

      heres a reduced version of my class:

       

       

      class com.sck.DragList extends MovieClip {

      //Declarations

      private var placeHolder:MovieClip;

      private var listMask:MovieClip;

       

       

      //Constructor

      public function DragList(PlaceHolder:MovieClip)

      {

      placeHolder=PlaceHolder;

      Init();

      }

       

       

      //Methods

       

      private function Init()

      {

      //placeHolder._visible=false;

      _x=placeHolder._x;

      _y=placeHolder._y;

      DrawListMask()

      }

       

       

      private function DrawListMask()

      {

      listMask = placeHolder.createEmptyMovieClip("listMask", this.getNextHighestDepth());

      listMask.name = "list";

      listMask.beginFill(0xcc00cc, 100);

      listMask.moveTo(0, 0);

      listMask.lineTo(placeHolder._width, 0);

      listMask.lineTo(placeHolder._width, placeHolder._height);

      listMask.lineTo(0, placeHolder._height);

      listMask.endFill();

      //listMask._alpha=0;

      listMask._x=placeHolder._x;

      listMask._y=placeHolder._y;

       

      //listMask.onMouseDown = Delegate.create(this, MouseDownOnList);

      //listMask.onMouseUp = Delegate.create(this, MouseUpOnList);

       

      this.addChild(listMask);

      }

      }

       

       

      Does anyone have any ideia that could help me? Thanks a lot!

        • 1. Re: Class extends MovieClip but can't call 'addChild'
          Rothrock Level 5

          I don't know Flash Lite 3.0, but you've posted in the AS1/2 forum and your code looks mostly like AS1/2, not AS3. What with the createEmptyMovieClip and the properties starting with _. So I'm going to go out on a limb and guess that the compiler knows what it is talking about when it tells you that there is no method with the name "addChild."

           

          addChild is not a method of the MovieClip class. It is a method of the DisplayObject class (I think, or at least something way up there in the heirarchy) and it does not exist is AS2.

           

          When you createEmptyMovieClip you are adding that instance to whichever moveclip instance you invoked it on. In this case the placeholder clip. Also with AS2 you can't reparent a clip to another.

          • 2. Re: Class extends MovieClip but can't call 'addChild'
            Paulo Ricca Level 1

            Hey

            Thank you for your attention. Actually Flash Lite 3.0 doesn't mean it's AS2 or AS3. It's just the Flash version like Flash 5 or Flash CS3.. As I said I'm using AS2

            There was something in my code that had also distracted you and it's my fault, because I had tryed so many different things that the code got messed up:

            I didn't want to create the empty movieclip inside the placeholder, that was just a test code, sorry, it was supposted to be this.createEmptyMovieClip

             

            And a colleague helped me out too, he gave me an idea to solve this problem: instead of called this.addChild, I'm calling super.addChild and it works! I'm not sure why the compiler needs the super because it isn't needed for the other methods such as getNextHighestDepth.. and it also works if i just cal addChild from outside the instance of the class.... Anyway, it's odd but it works with super

             

            Thanks anyway

             

             

            BUT now I have another problem... when I define the events:

            listMask.onMouseDown = Delegate.create(this, MouseDownOnList);

             

            private function MouseDownOnList()

            {

            trace("mouseDown");

            placeHolder._visible=true;

            }

             

            they don't work.. I click on the object and nothing happends :\ any ideias? sorry for asking another question that might not be directly related to my first problem

            • 3. Re: Class extends MovieClip but can't call 'addChild'
              Paulo Ricca Level 1

              Ok.. problem solves.. another problem arises :S the thing is, I can't use the mouseDown in Device Central because the touch screen isn't reacting to mouse clicks.. i'm going to search google for this.. thank you!