Closed GoogleCodeExporter closed 8 years ago
Clarification...
Actually, Type/ByteCodeType.forClass() does work! But,
Type/ByteCodeType.forInstance() fails (which is actually what I was
encountering in my real code).
Also, I think I see the possible cause...
The information returned by forClass shows that the fullName of Helper is
"Test.as$0.Helper". But, the Error thrown by forInstance complains about not
being able to find a class named "Test.as$0::Helper".
So, the issue might be that the library is using "::" instead of "." somewhere?
Revised example:
------------
// Test.as
package
{
import org.as3commons.bytecode.reflect.ByteCodeType;
public class Test extends Sprite
{
public function Test()
{
var t:ByteCodeType = ByteCodeType.forClass(Helper); // OK
ByteCodeType.forName(t.fullName); // OK
trace(t.fullName); // "Test.as$0.Helper"
ByteCodeType.forInstance(new Helper()); // ERROR!
}
}
}
class Helper { }
Original comment by idontneedthisacct@gmail.com
on 27 Jan 2011 at 8:58
Btw, for now, to avoid the ByteCodeType.forInstance failures on private/helper
classes, I am using the following work-around:
function byteCodeTypeForInstance(inst:*):ByteCodeType
{
var name:String = StringUtil.replace(getQualifiedClassName(inst), "::", ".");
return ByteCodeType.forName(name);
}
This seems to work for instances of any class.
Original comment by idontneedthisacct@gmail.com
on 27 Jan 2011 at 9:56
Thanks for bringing this up, the ByteCodeType.forName() will now first
normalize the class name before trying to retrieve it from the cache.
Original comment by ihatelivelyids
on 28 Jan 2011 at 12:05
What version will this fix appear in?
I am currently using...
as3commons-reflect-1.3.4.swc
as3commons-bytecode-0.9.7.swc
but ByteCodeType.forInstance() is still failing I as described in my previous
comments.
Original comment by idontneedthisacct@gmail.com
on 31 Jan 2011 at 11:07
I made some modifications in the trunk, (which I didn't test thoroughly I
readily admit), ByteCodeType.forClass() now checks if the clazz property is
null after retrieving it from the cache, if its null (in the case of private
classes) it will just assign the Class instance that was passed into the
forClass() method the the clazz property of the specified ByteCodeType instance.
This fix will appear in the next release.
Original comment by rol...@stackandheap.com
on 16 Mar 2011 at 10:01
Original issue reported on code.google.com by
idontneedthisacct@gmail.com
on 27 Jan 2011 at 7:54