代码:

 

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
  3.         layout="vertical" 
  4.         verticalAlign="middle" 
  5.         backgroundColor="white"> 
  6.  
  7.     <mx:Script> 
  8.         <![CDATA[  
  9.             private function openAllNodes():void {  
  10.                 tree.openItems = dp..node;  
  11.             }  
  12.  
  13.             private function closeAllNodes():void {  
  14.                 tree.openItems = [];  
  15.             }  
  16.         ]]> 
  17.     </mx:Script> 
  18.  
  19.     <mx:XML id="dp"> 
  20.         <root> 
  21.             <node label="Parent 1"> 
  22.                 <node label="Child 1" /> 
  23.                 <node label="Child 2"> 
  24.                     <node label="Grandchild 1" /> 
  25.                     <node label="Grandchild 2" /> 
  26.                 </node> 
  27.                 <node label="Child 3" /> 
  28.                 <node label="Child 4" /> 
  29.             </node> 
  30.         </root> 
  31.     </mx:XML> 
  32.  
  33.     <mx:ApplicationControlBar dock="true"> 
  34.         <mx:Button label="Open all nodes" click="openAllNodes();" /> 
  35.         <mx:Button label="Close all nodes" click="closeAllNodes();" /> 
  36.     </mx:ApplicationControlBar> 
  37.  
  38.     <mx:Tree id="tree" 
  39.             dataProvider="{dp}" 
  40.             showRoot="false" 
  41.             labelField="@label" 
  42.             width="200" /> 
  43.  
  44. </mx:Application> 
  45. <!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/  
  46.  
  47. Minified using disk  
  48. Page Caching using disk (enhanced) (request URI contains query)  
  49. Database Caching using disk  
  50. Object Caching 63/145 objects using disk  
  51.  
  52. Served from: blog.minidx.com @ 2012-08-06 07:42:29 --> 

效果:

http://blog.minidx.com/2009/02/24/2178.html