0 Replies Latest reply on Jun 15, 2006 1:22 AM by Newsgroup_User

    Do indexers exists in Actioscript 2.0

    Level 7
      Hello

      Indexers are also called smart arrays in C# and can be used to treat an
      object as an array. An indexer allows an instance of a class or a struct
      to be indexed as an array, which is useful for looping or iterating or
      data binding operations.

      The following is the syntax of an indexer declaration.

      <Modifier> <Return type> this[arguments]
      {
      get
      {
      }
      Set
      {
      }
      }

      I wonder if is posible to do this in actionscript:

      namespace ConsoleApplication
      {
      using System;

      class Employee
      {
      private string[]name = new string[10];
      public string this[int index]
      {
      get { return name[index]; }
      set { name[index] = value; }
      }
      }

      class Test
      {
      public static void Main()
      {
      Employee emp = new Employee();
      emp[0] = "Joydip";
      emp[1] = "Manashi";
      emp[2] = "Jini";
      Console.WriteLine("The namesare:--");
      for (int i = 0; i < 3;Console.WriteLine(emp[i++]))
      ;
      Console.ReadLine();
      }
      }
      }

      I am writing a Matrix class like this:

      class Matrix
      {
      private _data:Array;

      public function SetItem(row:Number, col:Number, value:Number):Void
      {
      _data[row][col] = value;
      }
      }

      To set matrix values I have to type:

      var myMatrix = new Matrix(3, 3);
      myMatrix.SetItem(0, 0, 1);
      ....

      And with indexers:

      myMatrix[0][0] = 1;

      Thanks.