Accessing data from a List item on mouse over

July 30, 2008 at 5:37 pm (Flex) (, )

Below is a short example in Flex on how to access data from a list item on mouse over. I’m using the rowIndex property of itemRollOver event to access the index at which the mouse is currently positioned.

<?xml version=”1.0″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”>

	<mx:Script>
		<![CDATA[
		    import mx.events.ListEvent;

		    var oceans:Array = ["Pacific", "Atlantic", "Indian", "Artic", "Southern"];

		    public function displayItem(event:ListEvent):void {
		    displayTxt.text = displayList.dataProvider[event.rowIndex];
		    }
		]]>
	</mx:Script>

	<mx:List id="displayList"
		dataProvider="{oceans}"
		itemRollOver="displayItem(event)" />

	<mx:TextArea id="displayTxt"/>

</mx:Application>

Permalink 1 Comment