ActionScript - Get Instance Name From Constructor Without Passing Parameters? -
is possible obtain instance name of class class without having manually pass instance name string parameter class constructor?
//create new sizeclass var big:sizeclass = new sizeclass(); //------------- package { public class sizeclass { public function sizeclass() { trace( //-- instance name "big" --// ); } } }
no, not possible know containing code block during constructor, save can learn stack trace (though that's not available except in debugger version of flash). if had global access point containing class, still not allow access.
think of constructor method call. in line of as, called before assignment. eg: var a:foo = new foo()
foo
created (the constructor completes), , a
populated whatever happened. after point a
remain agnostic of context (because of encapsulation) unless told (this true on displayobject -- try this( var mc:movieclip = new movieclip(); trace( mc.root ) //this null
).
i'm keeping because useful albeit not useful original answer.
you can name of class getqualifiedclassname
flash.utils
package. can't displayobject's until after has been constructed, can simulate (i believe) overriding function set name( value:string ):void
. if doesn't work, try finding after event.added
and/or event.added_to_sage
.
Comments
Post a Comment