09
Dec
07

Debugging Flex applications using the describeType() method and the ObjectUtil class

The following example shows how you can debug your Flex applications using the describeType() method (in the flash.utils package), as well as the static ObjectUtil.toString() method to display information about objects in Flex.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/12/09/debugging-flex-applications-using-the-describetype-method-and-the-objectutil-class/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="traceObj(progressBar);">

    <mx:Script>
        <![CDATA[
            import mx.utils.ObjectUtil;

            private function traceObj(target:Object):void {
                textArea1.text = ObjectUtil.toString(target);
                textArea2.text = describeType(target).toXMLString();
            }
        ]]>
    </mx:Script>

    <mx:Form width="100%" height="100%">
        <mx:FormItem label="target:">
            <mx:ProgressBar id="progressBar"
                    labelPlacement="center"
                    indeterminate="true" />
        </mx:FormItem>
        <mx:FormItem label="ObjectUtil.toString(...):"
                width="100%"
                height="50%">
            <mx:TextArea id="textArea1"
                    editable="false"
                    width="100%"
                    height="100%" />
        </mx:FormItem>
        <mx:FormItem label="describeType.toXMLString(...):"
                width="100%"
                height="50%">
            <mx:TextArea id="textArea2"
                    editable="false"
                    width="100%"
                    height="100%" />
        </mx:FormItem>
    </mx:Form>

</mx:Application>

View source is enabled in the following example.

There was an enhancement to the ObjectUtil class in Flex 3 (SDK build 187815 or later), where you can now use the ObjectUtil.toString() method on all display objects without getting a run time error.


5 Responses to “Debugging Flex applications using the describeType() method and the ObjectUtil class”


  1. 1 rconceiver Mar 4th, 2008 at 2:50 am

    Hi Peter rconceiver here again :)
    I tried the above code but it gives error on Flex 2 ad Flex 3 as well the error is
    “1061: Call to a possibly undefined method toString through a reference with static type Class.”

    Is there any way to see the structure of “Array of Object”
    i.e. var myArr:Array = new Array()
    for(var i:Number=0; i

  2. 2 peterd Mar 4th, 2008 at 7:08 am

    rconceiver,

    Odd, I got a different error in Flex 2 (”Error: Error #2099: The loading object is not sufficiently loaded to provide this information.”).
    But this worked for me in Flex 3 (Version 3.0 build 191831).

    Peter

  3. 3 rconceiver Mar 4th, 2008 at 8:55 pm

    Thanks Peterd,

    I tried that in Flex 3. Its working fone with data object the moment you add DisplayList reference in the object it doesn’t work.

    here is the link for more information.

    http://bugs.adobe.com/jira/browse/SDK-13419

    I still don’t understand how to solve this issue.. :(

  4. 4 peterd Mar 4th, 2008 at 10:14 pm

    Ah yes, I filed that bug. :)

    The bug was fixed in Flex 3 beta. What version of the SDK are you using? (Try typing “mxmlc -version” in your Flex SDK’s /bin/ directory.)

    Peter

  5. 5 rconceiver Mar 5th, 2008 at 2:23 am

    Thanks Peterd,
    I have updated flex sdk. the issue is no more there. I can see the structure of Object Array now. Thanks for that. :) I could see the try catch in file.
    But can we see some specific properties of DisplayList Object.?

    rconceiver

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".




December 2007
M T W T F S S
« Nov   Jan »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Badge Farm

  • Firefox 2
  • Powered by Redoable 1.2
  • Feeds burnt by Feedburner
  • Feed