0

Say you have a flexunit test that looks like this:

package foo {
    import flexunit.framework.TestCase;
    import flash.utils.getDefinitionByName;
    import flash.utils.getQualifiedSuperclassName;
    class DescribeTypeTest {
      public function testDescribeInnerType():void {
        var currentInstance:ChildBar = new ChildBar();
        trace(getDefinitionByName(getQualifiedSuperclassName(currentInstance)));
      }
    }
}
class Bar{}
class ChildBar extends Bar{}

Which throws the exception "Error #1065: Variable Bar is not defined." It only applies to inner classes (classes outside the package).

Does anyone have any way to get this to work?

victor hugo
  • 35,514
  • 12
  • 68
  • 79

2 Answers2

1

Not sure if there is any workaround, but just to confirm:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#getDefinitionByName():

getDefinitionByName () function
public function getDefinitionByName(name:String):Object Language Version : ActionScript 3.0 Runtime Versions : AIR 1.0, Flash Player 9 Returns a reference to the class object of the class specified by the name parameter.

Parameters

name:String — The name of a class. Returns Object — Returns a reference to the class object of the class specified by the name parameter.

Throws ReferenceError — No public definition exists with the specified name.

Since both Bar and ChildBar are non-public, you're getting that ReferenceError.

Juan Pablo Califano
  • 12,213
  • 5
  • 29
  • 42
0

I just tested following code with Flex 3.3 (AIR app):

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
    creationComplete="t();">
    <mx:Script>
        <![CDATA[
            import flash.utils.describeType;
            import flash.utils.getQualifiedSuperclassName;
            private function t():void {
                trace(getDefinitionByName(getQualifiedSuperclassName(new FooBar())));
            }
        ]]>
    </mx:Script>
</mx:WindowedApplication>

Bar.as

package
{
    public class Bar
    {
    }
}

FooBar.as

package
{
    public class FooBar extends Bar
    {
        public function FooBar()
        {
            super();
        }        
    }
}

As a trace result I see:

[SWF] DefTest.swf - 1,024,228 bytes after decompression
[class Bar]

Can you confirm this? Does that helps?

Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301
  • Can't be inside the package. The point is to load private (packageless) classes. –  Jun 17 '09 at 15:09