Everyone likes knowing about undocumented ActionScript. Discover the goodies in the _global property that Macromedia isn’t ready to officially support. (From the book, Flash Hacks, by Sham Bhangal, O'Reilly Media, 2004, ISBN: 0596006454.)
Undocumented ActionScript Flash Hack (Page 1 of 4 )
Hack 82: Undocumented ActionScript
Everyone likes knowing about undocumented ActionScript. Discover the goodies in the_globalproperty that Macromedia isn’t ready to officially support.
You’ll often want to examine the properties of an object to achieve a larger goal. For example, you might want to list an object’s property values in the Output panel for debugging purposes. Or you might want to decode the unknown properties of an object returned by, say, a server-side database call so you can parse the data intelligently. But this is a hacks book, so of course we want to enumerate (list) hidden properties of ActionScript to see if we can find any undocumented goodies.
ActionScript’s basic for...in loop effectively says to the Flash interpreter, “Look at the object of interest, and for each of its properties (including its methods stored within properties), execute the body of the loop once. And while you’re at it, tell me the name of the current property. Love the shoes, babe.”
However, many of ActionScript’s built-in methods and properties aren’t enumerable within a for...in loop by default. Macromedia assumes you want to see the objects and properties that your code creates, not the ones that underpin ActionScript, so they hid a lot of the built-in properties from being enumerated with for...in. However, the undocumented ASSetPropflags( ) function can make properties and methods visible even if they aren’t ordinarily enumerable within a for...in loop.
Macromedia has a habit of adding new functionality to late builds of earlier major releases. For example, many new Flash Player 7 features were undocumented and unsupported (but work!) in Flash Player 22.214.171.124. I check whether anything noteworthy has been added whenever Macromedia releases a new Flash Player, particularly if it’s late in the product’s lifecycle.
As its name suggests, ASSetPropFlags( ) allows you to set property flags within ActionScript. These flags tell the Flash Player whether to enumerate the specified methods and properties within a for...in loop.
You can also use ASSetPropFlags( ) to make your custom objects’ properties and methods unwritable (or unenumerable), so that no one can inadvertently overwrite them. This is especially true of global properties you might use in components you distribute to prevent conflicts with other third-party components used in the same SWF.
Okay, let’s have a quick look at how it works.
If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!