The Adobe docs state:
The IDs for all tags in an MXML component, no matter how deeply nested they are, generate public variables of the component being defined. As a result, all id properties must be unique within a document. This also means that if you specified an ID for a component instance, you can access that component from anywhere in the application: from functions, external class files, imported ActionScript files, or inline scripts.
Which is fine if your application is all contained within one MXML, but I'm having trouble referencing IDs of components within Modules, and then inside ViewStacks/Navigation Containers within a given Module.
For instance,
If I can reference a module with FlexGlobals.topLevelApplication.myModule, shouldn't I be able to reference a Panel called myModulePanel with the following?
FlexGlobals.topLevelApplication.myModule.myModulePanel
or at least
FlexGlobals.topLevelApplication.myModule.getChildByName(myModulePanel)
for properties such as title, width etc?
Since component IDs are public variables (according to the docs), I didn't think I'd have to chain a series of .getChildByName() functions to drill down into component/container levels to access component properties, but the methods I've tried above don't seem to be working.
But if this is the case, do I really need to form a long chain of component references to access the children of ViewStacks etc then- and what is the best way to inspect this hierarchy?
Any suggestions would be greatly appreciated.
Thanks.
You should create an interface for each module (or one main interface to which all your modules subscribe), defining methods that need to be called outside the modules. That way you interact with the interface, not the module itself, but the interface methods mediate between the module classes and the main application.
Using the
IModuleInfo
interface loaded by theModuleManager
should help you get to this. See this page for more info.Note that you can still create your own interfaces that give you control over the specific modules and their methods and properties. For example, I recently created an interface that returns a reference to two components (which are instances of
Group
but casts asUIComponent
):In the modules themselves, then, accessing the
mainGroup
orbuttonRow
properties of the interface returns the named Group, such as...
These are simplified and don't use the real IDs, but you should be able to get the idea from them.