In DHTML and AS2, we get away with doing this for setting node id's to
be global vars:
function setID ( id ){
//support for current system
if ((typeof(id) == 'string') && id.length) {
if ($debug) {
if (global[id] && global[id] !== this) {
Debug.warn('Redefining #%s from %w to %w',
id, global[id], this);
}
}
this.id = id;
// TODO: [2006-03-22 ptw] Should id's really go in the
user/canvas module?
global[ id ] = this;
} else {
if ($debug) {
// id is permitted to be null or undefined, meaning
// "don't id me"
if (id) {
Debug.error('Invalid id %w for %w', id, this);
}
}
}
//namespace system
//app[ id ] = this;
//local reference
}
This works because we aliased "global" to _root in AS2, and to
"window" in DHTML.
I don't see any way to do this in AS3. There doesn't seem to be any
magic object whose properties
become global vars. I'm not even sure how to get the runtime to set
global id variables by name procedurally during
instantiation even if we declare them. I hacked the tag compiler to
emit a list of top level var declarations for all id's, but
I don't see how to emit the code for the instantiator to bind to them
when the nodes are created, because what can you put on the
left side of the assignment?
One solution would be to make an API change, and require all globally
named nodes to be referenced via some object
like "lz", which we already are kind of pushing for class names. Tons
of user code would have to be updated.
To add one more twist of the knife, for the debugger eval mechanism,
if we want to use globals, we need to have a list of them
someplace to compile in to the little debugger stub template app,
because that code is compiled independent of the application code.
--
Henry Minsky
Software Architect
[EMAIL PROTECTED]