flex中绑定元数据

这篇文章算是flex初学者的的笔记吧,首先可以概览一下下文中的代码,然后我们主要是看看[Bindable]的这种用法。
这是一种将图片或者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]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | <?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> |



最新评论