6 Replies Latest reply: Apr 1, 2011 5:18 PM by kglad RSS

    Error found in custom class

    barpos Community Member

      Hi,

       

      I'm getting an error stemming from line 7 (public function below -- 1046: Type was not found or was not a compile-time constant: DisplayObjectContainer):

       

      ----------------------------------------------------------------------

       

      package
      {

       

          public class traceDisplayList
          {

       

              public function traceDisplayList(kontainer:DisplayObjectContainer, indentString:String=""):void
              {
                  var child:DisplayObject;
                  for (var i:uint = 0; i < kontainer.numChildren; i++)
                  {
                      child = kontainer.getChildAt(i);
                      trace(indentString,child,child.name);
                      if (kontainer.getChildAt(i) is DisplayObjectContainer)
                      {
                          traceDisplayList(DisplayObjectContainer(child),indentString + "");
                      }
                  }
              }

       

          }

       

      }

       

      Any idea?  I just can't see any errors on my part.

       

      Regards,

       

      Ron

        • 1. Re: Error found in custom class
          barpos Community Member

          I just tried the following way to call the class, but I still get the same error message:

           

          var myTrace:traceDisplayList = new traceDisplayList();
          myTrace.traceNow(stage);

           

          I renamed the public function to traceNow() thinking it might help.

          • 2. Re: Error found in custom class
            kglad CommunityMVP

            import that class:

             

             

            import flash.display.DisplayObjectContainer;

            • 3. Re: Error found in custom class
              barpos Community Member

              Makes sense!  A lot of the time the import statements come up automatically, for whatever reason.

               

              package
              {
                  import flash.display.DisplayObjectContainer;
                  import flash.display.DisplayObject;
                  public class traceDisplayList
                  {

               

                      public function traceDisplayList(kontainer:DisplayObjectContainer, indentString:String=""):void
                      {
                          var child:DisplayObject;
                          for (var i:uint = 0; i < kontainer.numChildren; i++)
                          {
                              child = kontainer.getChildAt(i);
                              trace(indentString,child,child.name);
                              if (kontainer.getChildAt(i) is DisplayObjectContainer)
                              {
                                  traceDisplayList(DisplayObjectContainer(child),indentString + "");
                              }
                          }
                      }

               

                  }

               

              }

               

              But, I have to admit, now it is the last line -- traceDisplayList() -- that bugs.  I'm told I have the wrong number of parameters.  Is this real?

               

              Regards,

               

              Ron

              • 4. Re: Error found in custom class
                kglad CommunityMVP

                that error message is misleading but you have screwy code.  try:

                 


                 

                package
                {
                    import flash.display.DisplayObjectContainer;
                    import flash.display.DisplayObject;
                    public class traceDisplayList
                    {

                 

                        public function traceDisplayList(kontainer:DisplayObjectContainer, indentString:String=""):void
                        {
                          traceF(kontainer,indentString);

                        }

                 

                private function traceF(kontainer:DisplayObjectContainer,indentString:String=""):void{

                  var child:DisplayObject;
                            for (var i:uint = 0; i < kontainer.numChildren; i++)
                            {
                                child = kontainer.getChildAt(i);
                                trace(indentString,child,child.name);
                                if (kontainer.getChildAt(i) is DisplayObjectContainer)
                                {
                                    traceF(DisplayObjectContainer(child),indentString + "");
                                }
                            }

                }

                 

                    }

                 

                }


                • 5. Re: Error found in custom class
                  barpos Community Member

                  I see, one cannot call recursively a public function.  I'll try to remember that.

                   

                  Thanks!

                   

                  Ron

                  • 6. Re: Error found in custom class
                    kglad CommunityMVP

                    it's not that it's public that's the problem.  the issue is that traceDisplayList is not a class method;  it's a class.