Categories Displayed in Flash

ByteArray brings back for…in, and Trace.me

Neato!

one of the useful utilities for AS2 for me was util.Trace.me which basically iterated over an object and gave you an output similar to (apologies WordPress is mangling my indentation, this is 3 layers deep):

[[[[ MyObject.displayObjmeAsArray() START nested: true ]]]]
+- a4:string = test
+- a2:Array = ,[object Object]
+-- 1:object = [object Object]
+- a5:object = [object Object]
+- a6:string = test
+- a8:string = test
+- a3:string = test
+- a10:object = [object Object]
+-- b1:object = [object Object]
+- a13:object = [object Object]
+-- a4:string = test
+-- a2:Array = ,[object Object]
+-- a5:object = [object Object]
+-- a6:string = test
+-- a8:string = test
+-- a3:string = test

this was invaluable when using SOS for getting to the bottom of an issue when the normal flash debugger wasn't an option. But of course with AS3 this really doesn't help as things are class based and you get pretty much nothing (or whatever describeType gives). But I figured out a workaround.
util.Trace.me has moved to com.troyworks.util.Trace, pass it a class and you will get a introspected view like:

+- pubUIntVar:uint = 1
+- pubNumVar:number = 0.5
+- pubIntVar:int = -1
+- pubBooTrueVar:boolean = true
+- pubStrVar:string = testString
+- pubBooFalseVar:boolean = false
+- pubDateVar:Date = Tue Aug 28 00:56:59 GMT-0700 2007
+- $$_id_:uint = 0

This is similar to for...in over normal objects/structs in AS2.

Note: only public vars (not static, const) are retrieved via this.

Note: $$_id_ isn't a part of the object, it's a remnant tag, is used to prevent circular infinite loops, marking the chain, since it's clone of the object, be it class or object based shouldn't be an issue, but not entirely sure how clone works with circular references/dependencies.

How it works is ByteArray to clone an Class which strips out the class definition, leaving it easy to traverse Object with a for...in loop.

What confuses me is how AMF serializes private data, yet ByteArray when back and forth doesn't. I can't tell if this is just security or a limitation.

Add a Comment: