3 Replies Latest reply on Mar 13, 2007 8:18 AM by Newsgroup_User

    Array problem???

    chenhsu
      I write a class as following:

      /* save in Foo.as */
      class Foo {
      private static var arr:Array;
      public function Foo() {
      Foo.arr = [];
      }
      public function addSomething(n:Number):Void {
      Foo.arr.push(n);
      }
      public function deleteSomething(n:Number):Void {
      Foo[arr.pop()];
      }
      public function showItToMe():Void {
      for (var i = 0; i<Foo.arr.length; i++) {
      trace("trace..."+arr );
      }
      }
      }
      And, write the following code in the first frame of test.fla file:
      var a:Foo = new Foo();
      var b:Foo = new Foo();
      a.addSomething(1);
      a.addSomething(2);
      b.addSomething(5);
      a.addSomething(3);
      a.addSomething(4);
      a.showItToMe();
      a.deleteSomething();
      a.showItToMe();
      b.addSomething(6);
      b.addSomething(7);
      b.addSomething(8);
      b.showItToMe();

      The result shows that a and b cannot have the independent arr(Array)?