2 Replies Latest reply on Feb 2, 2008 10:05 AM by Newsgroup_User

    Class Confusion

    Level 7
      Hello,

      This is a super simplified version of my problem, but supposing we have a
      class called Tester:

      class Tester {
      private var myFunc:Function;

      // constructor
      public function Tester(f:Function) {
      myFunc=f;
      }

      // public methods
      public function Execute() {
      myFunc();
      }
      }


      And in some code:

      var obj:Array=new Array();
      for (var i=1;i<=10;i++) {
      var fun=function() { trace(i); }
      obj =new Tester(fun);
      }

      obj[1].Execute();
      obj[2].Execute();

      How can I make it so the above two statements output:

      1
      2

      As opposed to (which is what it actually does)

      11
      11

      Is it possible?

      Thanks,
      Chris