Flex中通过describeType事件以及XMLListCollection获取TextArea控件所有属性的例子

By Minidxer | August 6, 2008

接下来的例子演示了Flex中如何通过describeType事件以及XMLListCollection,获取TextArea控件所有属性。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  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.         creationComplete="init();">
  7.  
  8.     <mx:Script>
  9.         private var xmlDebug:XML;
  10.  
  11.         private function init():void {
  12.             xmlDebug = describeType(targetObj);
  13.             xmlListColl.source = xmlDebug.accessor.(@declaredBy == xmlDebug.@name);
  14.         }
  15.  
  16.         private function labelFunc(item:Object, col:DataGridColumn):String {
  17.             var value:Object = targetObj[item.@name];
  18.             if (value == null) {
  19.                 return "(null)";
  20.             }
  21.             return value.toString();
  22.         }
  23.     </mx:Script>
  24.  
  25.     <mx:XMLListCollection id="xmlListColl">
  26.         <mx:sort>
  27.             <mx:Sort>
  28.                 <mx:fields>
  29.                     <mx:SortField name="@name" />
  30.                 </mx:fields>
  31.             </mx:Sort>
  32.         </mx:sort>
  33.     </mx:XMLListCollection>
  34.  
  35.     <mx:VDividedBox width="100%" height="100%">
  36.         <mx:TextArea id="targetObj"
  37.                 resize="init();" />
  38.  
  39.         <mx:DataGrid id="dataGrid"
  40.                 dataProvider="{xmlListColl}"
  41.                 color="black"
  42.                 width="100%"
  43.                 height="100%">
  44.             <mx:columns>
  45.                 <mx:DataGridColumn dataField="@access"
  46.                         itemRenderer="RedLabel" />
  47.                 <mx:DataGridColumn dataField="@name" />
  48.                 <mx:DataGridColumn labelFunction="labelFunc"
  49.                         headerText="value" />
  50.             </mx:columns>
  51.         </mx:DataGrid>
  52.     </mx:VDividedBox>
  53.  
  54. </mx:Application>
接下来是RedLabel.mxml代码:
Download: RedLabel.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Label xmlns:mx="http://www.adobe.com/2006/mxml" color="{(data.@access == 'readonly') ? 0xFF0000 : 0x000000}" />
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Flex | Tags: , , , , ,

Related Post

Leave a Comment

Name(*):

E-Mail(*) :

Website :

Comments :

Search Posts

Archives

Sponsored Ads