Actionscript 3 Code Snipplet of The Day: Enhanced “Typeof” Evaluation

typeof is handy but can be a little too flimsy at times.
Basically all it really understands are only six possible values;

and xml
If you want to run a conditional to check if you’ve got some common ethnic group, such as a movieclip, on your hands then it works charms… BUT if you want to use typeof to check for a Text Field, or maybe something more exciting, then it’ll fail.
At least I know of no other way…
Today’s super simple code blurb of the day is:

for (var i:Number=0; i<clip.numChildren; i++)
	var clips:Object = clip.getChildAt(i);
	if (clips.toString() == '[object TextField]')
		//do shit here
		trace("I'm a text field!");

The above loops through all nested movieclips inside of a parent movieclip and then checks what content is a text field. If it is then do what needs to be done… In this case just trace, because… trace is just what you do if you’re at a loss of what to do… ok!? Don’t judge me!

…Note that (clips.toString() == '[object TextField]') is the bit that you probably came googling here for. You can substitute clips for whatever the hell you need to check against. The above looping through the children movieclips is just for added karma points.
You have gained karma reading this.
You now have enough to confront the grue.