Flex中如何利用flash.utils中的describeType()和ObjectUtil.toString()来显示Flex中对象(Object)信息的例子

By Minidxer | January 1, 2009

接下来的例子演示了Flex中如何利用flash.utils中的describeType()和ObjectUtil.toString(),来显示Flex中对象(Object)信息。

让我们先来看一下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="traceObj(progressBar);">
  7.  
  8.     <mx:Script>
  9.         <![CDATA[
  10.             import mx.utils.ObjectUtil;
  11.  
  12.             private function traceObj(target:Object):void {
  13.                 textArea1.text = ObjectUtil.toString(target);
  14.                 textArea2.text = describeType(target).toXMLString();
  15.             }
  16.         ]]>
  17.     </mx:Script>
  18.  
  19.     <mx:Form width="100%" height="100%">
  20.         <mx:FormItem label="target:">
  21.             <mx:ProgressBar id="progressBar"
  22.                     labelPlacement="center"
  23.                     indeterminate="true" />
  24.         </mx:FormItem>
  25.         <mx:FormItem label="ObjectUtil.toString(...):"
  26.                 width="100%"
  27.                 height="50%">
  28.             <mx:TextArea id="textArea1"
  29.                     editable="false"
  30.                     width="100%"
  31.                     height="100%" />
  32.         </mx:FormItem>
  33.         <mx:FormItem label="describeType.toXMLString(...):"
  34.                 width="100%"
  35.                 height="50%">
  36.             <mx:TextArea id="textArea2"
  37.                     editable="false"
  38.                     width="100%"
  39.                     height="100%" />
  40.         </mx:FormItem>
  41.     </mx:Form>
  42.  
  43. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Other | No Comments » | 691 views Tags: , ,

Search Posts