(注:利用iconField只能更改叶子节点的图标。所以这里采用iconFunction) <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <!--[CDATA[ [Embed(source="folder.png")] //这是图片的相对地址 [Bindable] public var folder:Class; [Embed(source="workspace.png")] //这是图片的相对地址 [Bindable] public var workspace:Class; private function iconFun(item:Object):* { var xml:XML= XML(item); if(xml.attribute("type") == "folder") return folder; else if(xml.attribute("type") == "workspace") return workspace; } ]]--> </mx:Script> <mx:XML id="treedata"> <node label="ROOT"> <node label="Inbox" type="folder"> <node label="Marketing" type="workspace"/> <node label="Product Management" type="workspace"/> <node label="Personal" type="workspace"/> </node> <node label="Outbox" type="folder"> <node label="Professional" type="workspace"/> <node label="Personal" type="workspace"/> </node> <node label="Spam" type="workspace"/> <node label="Sent" type="folder"/> </node> </mx:XML> <mx:Tree width="398" height="300" x="98" y="52" showRoot="false" iconFunction="iconFun" dataProvider="{treedata}" iconField="@type" labelField="@label" /> </mx:Application>