Using trace function to print out all properties of an object in Flash
July 18, 2007
ActionScript3 | Actionscript 2 | Flash | Snippets | Web Building

The trace() function in flash is used much like alert() in Javascript. You can use it to print the contents of a variable or the result of an expression.

For example

var theNumber = 2
trace("theNumber= "+ theNumber)
output:
theNumber=2

Even more useful is the ability to print out ALL PROPERTIES of a clip, when you aren't sure what is there.


this.createTextField("someClip", this.getNextHighestDepth(), 0, 0, 100, 22);
for (var i in someClip) {
trace("someClip."+i+" = "+someClip[i]);
}

This can be used recursively to find the properties of one clip, then one of its children, etc.

I find this useful to determine the correct path to a target property when I am not sure which of the children of the current clip is the one that contains the target. If you aren't sure what properties or methods are associated with an object, this will display them.


Ads by Google

Posted by ellen at July 18, 2007 02:34 PM


Ads by Google

 RSS   |   Contact Me

Ads by Google

Ads by Google