Selecting an item in a datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tarik Monem
    New Member
    • May 2007
    • 63

    Selecting an item in a datagrid

    Hi Everyone,

    I've been trying to do this application that I've been working on from so many different angels and I seem to be running into some kind of wall with every attempt. I have scrapped each attempt and it should be easy, but it's not.

    I have simplified the app drastically by just having a datagrid being populated with the names of images from an array, which was populated via LoadVars. From there, I want to click on one of the cells(the name of an image) within the Datagrid and load the image into a MovieClip, but I continue to receive the message that "http://www.mydomain.co m/registration/images/undefined."

    image1 is my Loader on stage

    Here's the code
    Code:
    function defineListener() 
    {
    	var listener:Object = new Object();
    	listener.headerRelease = function(evt:Object) 
    	{
    	columnHighlight(evt.columnIndex);
    	};
    	listener.cellPress = function(evt:Object) 
    	{
    		getImage();
    		msg_ta2.text = "you clicked a cell";
    	}
    	dataGridMain.addEventListener("headerRelease", listener);
    	dataGridMain.addEventListener("cellPress", listener);
    }
    
    defineListener();
    
    function getImage() 
    {
       var cartGrid = dataGridMain;
       var someNumber:Number = cartGrid.getSelectedIndex();
    	var someWords:String = cartGrid.getSelectedItem;
       var imageSource:String = 'http://www.mydomain.com/registration/images/' + someWords;
       image1.load(imageSource);
    }
    I've tried to set someWords to cartGrid.select ed.data -- I've tried setting imageSource to imageAray[someNumber];

    But it always returns undefined? How can I successfully populate a datagrid and then not be able to retrieve the value of a particular cell?

    Thanks in advance
  • Tarik Monem
    New Member
    • May 2007
    • 63

    #2
    After a lot of reading over the internet, I came across this solution.

    Code:
    function defineListener() 
    {
    var myListener = new Object();
    	myListener.cellPress = function(eObj) 
    	{
    		 et = eObj.target;
    		 var cell = "(" + eObj.columnIndex + ", " + eObj.itemIndex + ")";
    		 // trace(" The cell at " + cell + " has been clicked ");
    		 // trace("Cell Text: " + et.getItemAt( eObj.itemIndex)[et.getColumnAt(eObj.columnIndex).columnName] );
    		 
    		 var imageSource:String = 'http://mydomain.com/registration/images/' +  et.getItemAt( eObj.itemIndex)[et.getColumnAt(eObj.columnIndex).columnName];
    		 image1.load(imageSource);
    	};
    dataGridMain.addEventListener("cellPress", myListener);
    }
    
     defineListener();

    Comment

    Working...