首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

flex 绑定元数据的步骤总结

2012-10-11 
flex 绑定元数据的方法总结这是一种将图片或者flash绑定为数据的方法。在代码中:?[Bindable]?[Embed(asset

flex 绑定元数据的方法总结

这是一种将图片或者flash绑定为数据的方法。在代码中:?
[Bindable]?
[Embed("assets/closed.png")]?
public var myFolderClosedIcon:Class;?
这三行代码是将clsed.png绑定为可用是数据。?
其中[Embed(...)]是叫做”元数据”?
注意,需要紧跟着要声明一个class变量,这个class在随后的代码中就代表了closed.png这个元素。?
最后看看在mxml中的调用:?
folderClosedIcon=”{myFolderClosedIcon}”?
我们看到在Tree组件中,直接调用了这个类作为tree中节点闭合时前面的ico图标。?
要绑定元数据还可以使用”元标签”[mx:Metadata]?
本文分析的代码如下:[此段代码的作用是改变Tree组件的列表图标ICO]?
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"?
layout="horizontal" viewSourceURL="srcview/index.html">?
<mx:Script>?
<![CDATA[?

[Bindable]?
[Embed("http://longstep.cn/closed.png")]?
public var myFolderClosedIcon:Class;?
[Bindable]?
[Embed("http://longstep.cn/opened.png")]?
public var myFolderOpenIcon:Class;?

[Bindable]?
[Embed("http://longstep.cn/pdf.png")]?
public var pdfIcon:Class;?
[Bindable]?
[Embed("http://longstep.cn/doc.png")]?
public var docIcon:Class;?

]]>?
</mx:Script>?
<mx:XML id="xmlData" xmlns="">?
<rootNode>?
<directory label="dir">?
<file icon="pdfIcon" label="label1" />?
<file icon="docIcon" label="label2" />?
</directory>?
<directory label="dir1">?
<file icon="pdfIcon" label="label3" />?
<file icon="docIcon" label="label4" />?
</directory>?
</rootNode>?
</mx:XML>?
<mx:Panel title="Tree">?

<mx:Tree?
borderStyle="none"?
backgroundAlpha="0"?
labelField="@label"?
iconField="@icon"?
width="300"?
height="200"?
id="treeAdmin"?
folderOpenIcon="{myFolderOpenIcon}"?
folderClosedIcon="{myFolderClosedIcon}"?
dataProvider="{xmlData.directory}" alpha="1" />?
</mx:Panel>?
</mx:Application>?

2.在<mx:script>中使用BindingUtil.bindProperty()方法。
我才学Flex,这是我总结的。

热点排行