Jiagao.net topleft
Welcome to jiagao.net
[认识自己]
Jiagao.net topright

[V2组件]labelFunction和iconFunction函数的使用

iconFunction:指定一个函数,该函数用于确定每行将使用哪个图标来显示其项目。此函数会接收参数item(该参数指示所呈现的项目),并且必须返回一个表示图标元件标识符的字符串。
V2中Button、List、Tree、Menu组件可使用该函数。用于处理数据显示项目图标。使用时必须定义该函数,即:
myComponent.iconFunction = function(itemObj) { 
   return itemObj.iconSymbolIdentifierName;
}


labelFunction:格式化显示组件的标签文本中的内容。
众多V2组件都可使用该函数。使用时必须定义该函数,即:
myComponent.labelFunction = function(itemObj) { 
   return itemObj.labelString;
}


下面通过例子介绍labelFunction、iconFunction的用法,简单的翻译了Ted的文章:
1、从组件面板中拖放一Tree组件到舞台,定义实例名称为:“myTree”
2、在关键帧上加上如下Action,用于载入XML文档,作为“myTree”组件的dataProvider。
dx = new XML(); 
dx.ignoreWhite = true;
dx.load("http://www.powersdk.com/sample/treedata.xml?"+Math.random()*10000);
dx.onLoad = function(){
   myTree.dataProvider = this.firstChild;
}

3、继续上面的Action,为“myTree”组件实例创建上面我们介绍的两个函数,这两个函数用于呈现myTree组件中的项目标签及图表。
// 返回作为tree组件项目的图标的影片剪辑的链接标识。
myTree.iconFunction = function(node){
   return node.attributes.icon;
}
// 返回“myTree”组件的项目标签内容。
myTree.labelFunction = function(node){
   if(node.attributes.title == undefined){
       return node.attributes.name + " (Division)";
   }else{
       return node.attributes.name + " (" + node.attributes.title + ")";
   }
}

4、完工,测试。

相关链接:
下载源码
Ted的原文以及效果预览
2004年10月08日, 星期五 21:25:24

评论

暂时没有评论

发表评论

姓名:    
电邮:    
网址:    
评论:(500字符 禁止HTML)

Remember Me Show Email