iconFunction和labelFunction的补充,以前看过Jiagao's Blog上的《labelFunction和iconFunction函数的使用》。又想起了做了如下实验:
myList.dataProvider = [{label:"生活照", data:{fileName:"myphoto1", fileExtension:"jpg"}}, {label:"学习笔记", data:{fileName:"myDocument2", fileExtension:"doc"}}, {label:"产品照片", data:{fileName:"myphoto2", fileExtension:"gif"}}, {label:"临时文本", data:{fileName:"myDocument1", fileExtension:"txt"}}];
myList.labelFunction = function(item) {
return (item.label+"("+item.data.fileName+"."+item.data.fileExtension+")");
};
myList.iconFunction = function(item) {
var type = item.data.fileExtension;
if (type == "jpg" || type == "gif") {
return "pictureIcon";
} else if (type == "doc" || type == "txt") {
return "docIcon";
}
};
iconFunction是ScrollSelectList的一个方法,所以作为ScrollSelectList的子类的List、Menu及List的子类的Tree和DataGrid也应该又同样的方法(Menu的方法是FLASH帮助中没有的,云开让我看MM的V2的类真的是非常有用啊)
labelFunction有很多组件都可以使用,如List、Menu、Tree、DataGrid、DataGridColumn、MenuBar、ComboBox及他们的子类。(FLASH帮助里又没有Menu的提及labelFunction方法)
大家可以从下面的代码
var myMDP = new XML();
var newItem = myMDP.addMenuItem({label:"New"});
newItem.addMenuItem({label:"File..."});
newItem.addMenuItem({label:"Project..."});
newItem.addMenuItem({label:"Resource..."});
myMDP.addMenuItem({label:"Open", instanceName:"miOpen"});
myMDP.addMenuItem({label:"Save", instanceName:"miSave"});
myMDP.addMenuItem({type:"separator"});
myMDP.addMenuItem({label:"Quit", instanceName:"miQuit"});
var myMenu = mx.controls.Menu.createMenu(myParentClip, myMDP);
//
myMenu.iconFunction = function(item) {
switch (item.attributes.label) {
case "New" :
case "File..." :
case "Save" :
return "docIcon";
break;
default :
return "pictureIcon";
break;
}
};
myMenu.show(250, 10);
本文地址:http://com.8s8s.com/it/it23865.htm