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.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

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

  1. rconceiver says:

    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. peterd says:

    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. rconceiver says:

    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. peterd says:

    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. rconceiver says:

    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

  6. Matteo Lanzi says:

    did you find any solution to get the list of all the mx_internal properties ?

    Teo

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree