2 Replies Latest reply on Aug 26, 2006 7:15 AM by optimalweb

    Reference Flex Stage From AS Class

    optimalweb Level 1
      I have an AS2 Class that I am converting to AS3. There are several functions which used to reference _root to get a list of objects from the main "stage". I am having trouble finding a reference from the class to the main application.

      Specifically, this is what I would like to do:

      In the AS3 class, I want to reference the main application's stage display list and parse through it. For example, if I were using the following code from http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=L iveDocs_Parts&file=00001853.html in an AS3 class, and I wanted to parse through the DisplayList of the main application's stage objects, how could I reference the main application stage without having to pass the objects through from the main application?

      The following code works if it is part of the main application, but using 'this' in the function call doesn't work, nor does the use of 'stage' if this same code is moved to and AS class and imported into the main application.

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

      traceDisplayList(this);

      Any suggestoins? Am I just approaching this the wrong way?

      Thank you.