2 Replies Latest reply on Nov 8, 2006 4:31 PM by arkcto

    Datagrid not populated programatically


      I am trying to populate a datagrid in ActionScript, but am unable to do. However, if I do it in mxml, I am able to see the data.

      Here is my relevant mxml code.
      public var players:ArrayCollection;

      private function fillPlayers(event: ArrayCollection):void {
      players = event;
      mainTxt.text = "Getting filled later";

      private function displayRackInfo():void {
      playMe.getPlayersAsList(); // This fills the players collection.

      var rackInfoGrid:DataGrid = new DataGrid();
      rackInfoGrid.dataProvider = players;

      var firstName:DataGridColumn = new DataGridColumn("firstName");
      var lastName:DataGridColumn = new DataGridColumn("lastName");
      var rackColumns:Array = new Array(firstName, lastName);

      rackInfoGrid.columns = rackColumns;

      if (players == null) {
      mainTxt.text = "NULL"; // Print NULL in TextArea box

      if (players != null) {
      mainTxt.text = "NOT NULL"; // Print NOT NULL in TextArea box

      PopUpManager.addPopUp(rackInfoPanel, this, true);

      <mx:RemoteObject id="playMe" destination="PlayerService">
      <mx:method name="getPlayerList" result="fillPlayers(event.result as ArrayCollection)"/>

      PlayerService code is below :

      public List getPlayersAsList() {
      System.out.println("List method called");
      List players = new ArrayList();
      Player michael = new Player("Michael","Jordan");
      Player scottie = new Player("Scottie","Pippen");
      return players;

      The datagrid shows headers, but no data. Also my print messages show that the remote service is being called. Also in my action script method, once I get the 'NULL' message and another time, I get the 'NOT NULL' message.

      If I take the datagrid out of ActionScript and populate it in mxml, it works just fine. I see the entire data.

      <mx:DataGrid dataProvider="{players}" height="100" width="100%">
      <mx:DataGridColumn dataField="firstName" headerText="FirstName"/>
      <mx:DataGridColumn dataField="lastName" headerText="LastName"/>

      The reason I am trying to do in ActionScript is because i want the datagrid to open only when a user event happens. User clicks a button, and then the datagrid pops up. If I do it in mxml, I am unable to get that behaviour. Datagrid is visible right from the start of the application.

      Please help.