0 Replies Latest reply on Jan 18, 2010 5:52 PM by GapingWound

    Hilighting GridRow

    GapingWound

      Howdy everyone,

       

      I'm programatically creating a Grid, and have a TextEvent.LINK handler that passes an ID back out to javascript in the parent application. What I'm having a hard time doing is changing the background color of the clicked row.

       

      Can anyone tell me what I'm doing wrong?

       

          private function initApp():void{
         
              var result:String = Application.application.parameters.result;
              // start cell number
              var cellNum:Number = 0;
         
              // split the incoming data into rows
              var rows:Array = result.split ( "[END]" );
              for( var i:int = 0; i < rows.length-1; i++ )
              {
                  // create a new grid row
                  arow = new GridRow();
                  arow.id = "row_"+i;
                  if ( i%2 == 0 )
                  {
                      arow.setStyle("backgroundColor",0x000000);
                  } else {
                      arow.setStyle("backgroundColor",0x222222);
                  }
                  arow.percentWidth = 100;
                  // split the data row into cells
                  var cells:Array = rows[i].split( "|" );
                 
         
                  // add the Artist cell
                  arrOfCellObj[cellNum] = new GridItem();
                  txt = new Text();
                  txt.addEventListener(TextEvent.LINK, selectSong);
                  txt.id = "cell_"+cellNum;
                  txt.htmlText = "<a href='event:"+cells[0]+"'>"+cells[1]+"</a>";
                  txt.width = 450;
                  arrOfCellObj[cellNum].addChild(txt);
                  arow.addChild(arrOfCellObj[cellNum]);
                  cellNum++;
         
                  // add the Album cell
                  arrOfCellObj[cellNum] = new GridItem();
                  txt = new Text();
                  txt.addEventListener(TextEvent.LINK, selectSong);
                  txt.id = "cell_"+cellNum;
                  txt.htmlText = "<a href='event:"+cells[0]+"|"+i+"|"+rows.length+"'>"+cells[2]+"</a>";
                  txt.width = 350;
                  arrOfCellObj[cellNum].addChild(txt);
                  arow.addChild(arrOfCellObj[cellNum]);
                  cellNum++;
                 
                  myGrid.addChild(arow);
              }
          }
          public function selectSong(event:TextEvent):void
          {
              var parts:Array = event.text.split ( "|" );
              for( var i:int = 0; i < parts[2]; i++ )
              {
                  var elem:GridRow = this["row_"+i];
                  if ( i%2 == 0 )
                  {
                      elem.setStyle('backgroundColor',0x222222);
                  } else {
                      elem.setStyle('backgroundColor',0x000000);
                  }
                  if ( i == parts[1] )
                  {
                      elem.setStyle('backgroundColor',0x666666);
                  }
              }
              if (ExternalInterface.available)
              {
                  ExternalInterface.call("selectSong", parts[0]);
              }
          }

       

      Thanks,

      Keith