mx_internal
go see mx.core.mx_internal.This isn't so much undocumented as it is a hack. I wouldn't do it, but it's still fun.
Actually this technique seems pretty obvious once it occurs to you. Since something under the internal namespace can only be accessed from within the same package, just put your own class with proxy functions in that package.
So the obvious question becomes, what if the the internal function you want to access is in an swc? If this is a case you can't just insert a class into it. But you can create mimic the package structure in your own project and put the class there. This will work fine.
So let's say you want to call
form.invalidateLabelWidth()
which happens to be marked internal. In your own project simply create the directory structure, mx.containers. In this new containers folder put create a class "FormInternalProxy", and then create the function:public static function invalidateLabelWidth(form:Form):void {
form.invalidateLabelWidth();
}
It's that simple. I'm still looking into if something like this can be used to access private functions, but so far class naming conflicts seem to prevent it.
2 comments:
Exactly the trick I'm looking for! Thank you!
Looking for a way to modify private variables runtime from outside the private scope?
- Only works in debugplayer.
- Crashes on read only variables (add try..catch to prevent)
- Crashes on int, boolean (non-object objects)
trace(getLocalVariableFromObject(myObject, "myPrivateVariable"));
(you can also use this to call private functions)
public static function getLocalVariableFromObject(object:Object, variableName:String):Object
{
var members:Array = getMemberNames(object,false);
for each (var member:QName in members)
{
if (member.localName == varaiableName)
{
return this[object];
}
}
return null;
}
Post a Comment