-
Notifications
You must be signed in to change notification settings - Fork 8
Introspection
While most commonly used to call methods through commands and print messages through logging, DConsole has some fairly powerful introspection capabilities.
What this means is that at any time, the console is capable of acquiring and manipulating variables, functions and accessors on arbitrary objects in the application context, without needing to be mapped to those elements ahead of time with createCommand.
The console introspection treats the structure of the host Flash application similar to the way Windows cmd.exe or OSX terminal treats a file system. The console has a "current scope", being the element of the application structure it is currently focused on. That scope contains fields such as variables and methods, and the console can access those fields with the commands get, set and call, as well as others found under the Introspection category. Furthermore, if a field is of complex type, that is it has fields of its own, you can set the current scope to that field using the command select. Metaphorically, you can think of select as cd.
If the current scope is a DisplayObject, you can move the current scope to its parent with the command parent, and if the current scope has DisplayObject children, you can select them using their instance names.
This allows you to crawl your application from the root up, to get at objects you want to interact with freely. You can also select objects as the current scope using DConsole.select; It's conceivable you'll want to create your own tools for interactively selecting on-screen displayobjects.
Beware the console doesn't keep a stack of selections by default. This means it's possible to paint yourself into a corner, such as by selecting an object that has no pointer to its parent, such as an Array. A selection history can be enabled through the SelectionHistoryUtil plugin, adding a back command.
Setting the current scope to the application root >> root
Selecting a child displayobject >> select instance4212
Examining its position >> get x << 0 >> get y << 0
Setting its position >> set x 20 << 20 >> set y 40 << 40
Going back to its parent again >> parent
Selecting a child via a class method through a [subcommand](Commands] >> select (call getChildByName myDisplayObject)
Selecting an array class member and accessing its fields. In this case, the array has two string elements. >> select myArray >> get 0 << First >> get 1 << Second >> get 4921 << TypeError: Error #1010: A term is undefined and has no properties.