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

by Peter deHaan on December 9, 2007

in ObjectUtil

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.

{ 6 comments… read them below or add one }

1 rconceiver March 4, 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

Reply

2 peterd March 4, 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

Reply

3 rconceiver March 4, 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.. :(

Reply

4 peterd March 4, 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

Reply

5 rconceiver March 5, 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

Reply

6 Matteo Lanzi April 15, 2009 at 5:58 am

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

Teo

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can 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

Previous post:

Next post: