Question
Accessing selected Item of a lIst
Hi,
I'm trying to access the selected item idex label of a click list.
I normally havn' t had any trouble with this before. I seem to be having a problem because the list is inside a movie clip.
First of all I attach a movieclip containing a list to a container
///////////////////////////////////////////////////////////////////////
var player:Object = getDefinitionByName("Player") as Class;
var clipPlayer:MovieClip = new player();
clipPlayer.name="player"
clipPlayer.x=200;
clipPlayer.y=200;
Container.addChild(clipPlayer);
//////////////////////////////////////////////////////////////////////////
Then I add data to the list
///////////////////////////
var temp:Array=arr;
for (var i=0; i<temp.length; i++) {
var obj:Object=temp ;
var id:int =obj.ID;
var d:String=obj.Name;
var s:String=obj.SourcePath;
//trace("test"+d+"***")
var c=Container.getChildAt(0);
c.clipListBox.addItem({label:d,data:s});
c.clipListBox.addEventListener(ListEvent.ITEM_CLICK,clipItemClicked);
}
/////////////////////////
In the last line of the above code I have added an event listener named clipItemClicked.
The problem I have is in the handler for this listener.
////////////////////////////////////
public function clipItemClicked(e:ListEvent):void
trace(e.target.selectedItem.label);
}
///////////////////
When I try the above code (which I think is fairly standard) I get the following error and I dont understand why?
TypeError: Error #1009: Cannot access a property or method of a null object reference.
As far as I can see the property is not null because the list is displaying data. I'm not sure what the whole null object reference thing means.
Any ideas why I'm getting this error?
Thanks
dub
I'm trying to access the selected item idex label of a click list.
I normally havn' t had any trouble with this before. I seem to be having a problem because the list is inside a movie clip.
First of all I attach a movieclip containing a list to a container
///////////////////////////////////////////////////////////////////////
var player:Object = getDefinitionByName("Player") as Class;
var clipPlayer:MovieClip = new player();
clipPlayer.name="player"
clipPlayer.x=200;
clipPlayer.y=200;
Container.addChild(clipPlayer);
//////////////////////////////////////////////////////////////////////////
Then I add data to the list
///////////////////////////
var temp:Array=arr;
for (var i=0; i<temp.length; i++) {
var obj:Object=temp ;
var id:int =obj.ID;
var d:String=obj.Name;
var s:String=obj.SourcePath;
//trace("test"+d+"***")
var c=Container.getChildAt(0);
c.clipListBox.addItem({label:d,data:s});
c.clipListBox.addEventListener(ListEvent.ITEM_CLICK,clipItemClicked);
}
/////////////////////////
In the last line of the above code I have added an event listener named clipItemClicked.
The problem I have is in the handler for this listener.
////////////////////////////////////
public function clipItemClicked(e:ListEvent):void
trace(e.target.selectedItem.label);
}
///////////////////
When I try the above code (which I think is fairly standard) I get the following error and I dont understand why?
TypeError: Error #1009: Cannot access a property or method of a null object reference.
As far as I can see the property is not null because the list is displaying data. I'm not sure what the whole null object reference thing means.
Any ideas why I'm getting this error?
Thanks
dub