2

For some irrelevant reasons I need a class:

  1. that inherits (directly or not) from MovieClip.
  2. that implements a particular interface (let's assume here that this interface is empty since it does not change anything to the issue).
  3. and whose .as file declares internal classes.

The following code sums this up:

package {
    import flash.display.MovieClip;
    public class MyClass extends MovieClip implements EmptyInterface { }
}

class MyInnerClass { }

The problem with that code above is that it will not always compile. As soon as I use MyClass as Linkage for one of my library's item the compiler complains about MyClass not being a subclass of MovieClip. On the other hand, everything works great if I instantiate it manually and add it to the stage.

It looks like the interface and the inner class are somehow mutually exclusive in that very particular case. Indeed, if I remove the inner class I do not have that error anymore:

package {
    import flash.display.MovieClip;
    public class MyClass extends MovieClip implements EmptyInterface { }
}

Same thing when I remove the implemented interface but keep the inner class:

package {
    import flash.display.MovieClip;
    public class MyClass extends MovieClip { }
}

class MyInnerClass { }

Note that I've only tested this in Flash CS5.

Antoine M.
  • 23
  • 2
  • My guess would be that EmptyInterface is blocking some of the MovieCLips functions that when linked the compiler is testing for. – The_asMan Jul 16 '12 at 14:23
  • The inner class might cause problems, because it is default-scoped to `internal`, while in the top level package. Have you tried using a fully qualified package name? – weltraumpirat Jul 16 '12 at 16:10
  • @The_asMan Not sure to understand what you said but, if the interface is the cause of the problem, why is the code working when I remove the inner class declaration and keep the interface ? – Antoine M. Jul 17 '12 at 07:29
  • @weltraumpirat I did try with packages that aren't top level and the error is still raised (5000: The class 'src.MyClass' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.) – Antoine M. Jul 17 '12 at 07:34

3 Answers3

1

I say it is a bug of compiler.

I have tested and found that private class must extend any class that is not Object. Instead of extending class it can also implement any interface.

This works same even if I put classes into deeper package.

I have tested this with Flash CS6.

Rytis Alekna
  • 1,387
  • 7
  • 17
  • +1 I've also tested it and came to the same conclusion. The inner class is not `private`, though (in fact, classes can *never* be `private`); omitting the visibility keyword defaults to `internal`. Good thing, too: The class can therefore be moved to a separate file without affecting the resulting binary - which also works for the compiler, even when not extending `Object`. – weltraumpirat Jul 17 '12 at 15:41
  • I've tested it as well and it indeed works. As soon as the inner class extends (or implements) anything else but `Object` the compiler does not complain about the **other** class not being a subclass of `MovieClip`. Compiler bug it is. – Antoine M. Jul 18 '12 at 07:59
0

If I'm reading you right, you want a public class to extend an internal class? - There is nothing that prevents you from doing this, so long as you declare your internal class as it's own packaged file.

According to the documentation:

[dynamic] [public | internal] [final] class className [ extends superClass ] [ implements interfaceName[, interfaceName... ] ] { 
    // class definition here
}



If it's the interface that is giving you grief, have you declared it in a separate file as well - that you would import? As eluded to in the comments, the namespace scoping is important so that the compiler understands what the escalating priority is.

Eg:

package my.example {
   public interface EmptyInterface
   {
   }
}

So that:

package {
    import flash.display.MovieClip;
    import my.example.EmptyInterface;
    public class MyClass extends MovieClip implements EmptyInterface { }
}
Mike Petty
  • 949
  • 6
  • 6
0

If this doesn't fix it I have another idea but try this first.
Click file
Click publish setting
Click on settings button
Uncheck Automatically declare stage instances
Click OK

The_asMan
  • 6,364
  • 4
  • 23
  • 34