0 Replies Latest reply on Jul 24, 2007 12:41 PM by Tarindel

    MXML component arrays?

    Tarindel
      The Flex program I am writing has multiple MXML components of the same type, each of which has a unique ID:
      <ns1:PlayerBoard id="PlayerBoard1" y="0"/>
      <ns1:PlayerBoard id="PlayerBoard2" y="150"/>
      <ns1:PlayerBoard id="PlayerBoard3" y="300"/>
      <ns1:PlayerBoard id="PlayerBoard4" y="450"/>
      <ns1:PlayerBoard id="PlayerBoard5" y="600"/>

      I would like to access these via an array, but I can't figure out how. I successfully created an array:

      var PlayerBoard:Array = [PlayerBoard1, PlayerBoard2, PlayerBoard3, PlayerBoard4, PlayerBoard5];

      However, when I try to use the array, it doesn't work:
      PlayerBoard[1].SetValue(5);

      My workaround is to define a function like this:
      public function GetPlayerBoard(nPlayer:int) : Components.PlayerBoard
      {
      switch (nPlayer)
      {
      case 1: return PlayerBoard1;
      case 2: return PlayerBoard2;
      case 3: return PlayerBoard3;
      case 4: return PlayerBoard4;
      case 5: return PlayerBoard5;
      default:
      throw new Error("Invalid player called in GetPlayerBoard().");
      }
      }

      And this seems to work fine. But I'd still prefer to have access via an array. Is it possible?