2 Replies Latest reply on Feb 1, 2009 7:26 AM by richard.szalay

    Subclassing nested (private ns) classes at runtime

    richard.szalay Level 1
      A question for the AVM2 engineers here.

      I am the author of asmock, a dynamic object mocking framework, and am looking at a few features to add before 1.0. One of the biggest features I'd like to support is the ability to mock a "nested" (private namespace) class.

      I know that subclassing a nested class outside the "code file" is illegal, but I have assumed that the AVM will let me do it as long as I setup the DoABC tag correctly.

      Based on dumps of valid SWFs that do this, there does not seem to be anything special about the classes. Both the child and the parent are declared with a private ns multiname (0x05) and the members are declared as public traits of the class. The ns used is copied directly from the parent (for nested classes), and is always "Filename.as$number". However, during loadBytes, I get a ValidateError: "Class MockRepositoryNestedClassIntegrationFixture.as$452::NestedClass could not be found".

      Is there anything I might have missed? Or, alternatively, is there an explicit AVM restriction that nested classes can only be subclassed within the SWF they were loaded from?

      Many thanks,
      Richard
        • 1. Re: Subclassing nested (private ns) classes at runtime
          Level 7

          "richard.szalay" <webforumsuser@macromedia.com> wrote in message
          news:gm3rfo$f0h$1@forums.macromedia.com...
          >A question for the AVM2 engineers here.
          >
          > I am the author of http://asmock.sourceforge.net/, a dynamic object
          > mocking
          > framework, and am looking at a few features to add before 1.0. One of the
          > biggest features I'd like to support is the ability to mock a "nested"
          > (private
          > namespace) class.
          >
          > I know that subclassing a nested class outside the "code file" is illegal,
          > but
          > I have assumed that the AVM will let me do it as long as I setup the DoABC
          > tag
          > correctly.
          >
          > Based on dumps of valid SWFs that do this, there does not seem to be
          > anything
          > special about the classes. Both the child and the parent are declared with
          > a
          > private ns multiname (0x05) and the members are declared as public traits
          > of
          > the class. The ns used is copied directly from the parent (for nested
          > classes),
          > and is always "Filename.as$number". However, during loadBytes, I get a
          > ValidateError: "Class
          > MockRepositoryNestedClassIntegrationFixture.as$452::NestedClass could not
          > be
          > found".
          >
          > Is there anything I might have missed? Or, alternatively, is there an
          > explicit
          > AVM restriction that nested classes can only be subclassed within the SWF
          > they
          > were loaded from?

          I think you're more likely to find someone who knows the framework and the
          player in this kind of detail on the flexcoders yahoo group.


          • 2. Re: Subclassing nested (private ns) classes at runtime
            richard.szalay Level 1
            Thanks Amy, I'll shoot the question over to that group and see if I have any luck.

            To anyone else still monitoring the question here, an update:

            I realised that I was not marking my child class with the protected_namespace flag. I added this (and the ns to go with it), and now my generated BC looks the same as it does in the source swf. Unfortunately, I still get the same error as above.

            Any help would be appreciated.