import fl.data.DataProvider;
import fl.controls.List;
var urlLoc:String = new String();
var dp:DataProvider = new DataProvider();
for (var i:uint = 1; i<=5; i++){
dp.addItem( { label:"Channel" +i ,ben : "musicList"+i+".xml"} );
}
var list:List = new List();
list.dataProvider = dp;
addChild(list);
list.setSize(140,60);
list.addEventListener(MouseEvent.CLICK, action);
function action(e:MouseEvent):void{
urlLoc = e.target.data.ben;
trace(urlLoc);
}
Its working fine and when I am click the down and up but开发者_如何学编程ton its brings me an error.
"ReferenceError: Error #1069: Property data not found on fl.controls.BaseButton and there is no default value. at Untitled_fla::MainTimeline/action() "
How could I solve this problem?
I don't think List has a property data. I guess you want to get the selected item. please try:
urlLoc = e.target.selectedItem.ben;
U made a problem with listener Object.
Change the event Handler Event.CHANGE
instead of "MouseEvent.CLICK
".
list.addEventListener(Event.CHANGE, action);
It seems like the button event is bubbling though the List. Do you want the event listener to fire on the up and down buttons or just on the list itself?
You could try:
function action(e:MouseEvent):void{
if(evt.target is List) {
urlLoc = e.target.data.ben;
trace(urlLoc);
}
}
精彩评论