0 Replies Latest reply on Aug 23, 2007 5:52 AM by Newsgroup_User

    How to access an object from a class without DisplayObject

    Level 7
      I've created two classes: ABC and XYZ

      The class ABC extends Sprite and I declare it like this:

      for (var i:int=0; i<5; i++) {
      var abc:ABC = new ABC();
      abc.name = "abc_"+i;
      abc.setData(i);
      this.addChild(abc);
      }

      If I want to have access to it, I do something like this:

      for (var j:int=0; j<5; j++) {
      trace(ABC(this.getChildByName("abc_"+j)).getData());
      }


      The class XYZ it's a "standalone" class that does not extends or import
      any other class, and here it is how I declare it:

      var xyz_01 = new XYZ();
      xyz_01.addValue('anyValue');

      trace(xyz_01.getValue());

      BUT, if I can't figure how to declare it and/or reference to it dynamically.

      for (var i:int=0; i<5; i++) {
      this['abc_0'+i] = new XYZ();
      this['abc_0'+i].addValue('anyValue');
      }

      for (var j:int=0; j<5; j++) {
      trace(this.getChildByName('abc_0'+j).getValue()); // seems that
      getChildByName does not work because it the object doesn't have a name
      and is not added as a child on the stage
      trace(this['abc_0'+j].getValue()); // this one only works if I replace
      the "j" for a "4" (abc_04 was the last one created) otherwise I get
      "TypeError: Error #1010"
      }

      So, it could be declared correctlt, but since I can't use their methods
      I cannot tell, any clues on this?

      regards.