Getting [Object Object] when doing getItemAt() in List
I have set my data provider as Bindable
as such:
[Bindable]
public var dataProvider:ArrayCollection;
public function init():void{
dataProvider = new ArrayCollection(
[{label:"x"},
{label:"y"},
{label:"z"}]);
Then in a function called upon CLick event of a button, I want to get the item at a particular index
private function getmyItem(event:Event):void {
trace(dataProvider.length);
trace(dataProvider.getItemAt(1));
//OR
trace(dataProvider.getItemAt(myList.selectedIndex));
}
But I am getting [Ob开发者_运维百科ject Object]
in my trace. Can someone tell me what is the prob with my code?
Thanks
your code is not complete
trace(dataProvider.getItemAt(myList.selectedIndex).label);
trace("your_tilelist_name".dataProvider.getItemAt(myList.selectedIndex).label);
private function getmyItem(event:Event):void {
trace("your_tilelist_name".dataProvider.length);
trace("your_tilelist_name".dataProvider.getItemAt(1).label);
//OR
trace("your_tilelist_name".dataProvider.getItemAt(myList.selectedIndex).label);
}
It is not any obvious what do you want to get in trace
but I can guess the following fixes can solve your problem:
private function getmyItem(event:Event):void {
trace(dataProvider.length);
trace(dataProvider.getItemAt(1).label);
//OR
trace(dataProvider.getItemAt(myList.selectedIndex).label);
}
{label:"x"},
{label:"y"},
{label:"z"}
These are Objects
created using {}
syntax.
var obj:Object = {some:"value"};
trace(obj); // [object Object]
精彩评论