這是一種將圖片或者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]
複製代碼 代碼如下:<?xml version="1.0" encoding="utf-8"?>
<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>