PDA

View Full Version : Interfaces in a different path (package)



Ayman
July 26th, 2008, 11:16 PM
In my class, how can I implement an interface that is lieing in a different path (not in the same package) ? I tried to import but it failed. From the flash documentation it said that interfaces should not lie inside a package. How authentic is that?

TheCanadian
July 27th, 2008, 05:52 AM
I can import them from a package.


package test {
public interface ITest {}
}

package {
import test.ITest;
public class Test implements ITest {}
}

import test.ITest;

var t:Test = new Test();
trace(t is ITest); //true

Ayman
July 27th, 2008, 07:47 AM
hmmm so it goes under a package name ...
The flash documentation should have mentioned something like that

senocular
July 27th, 2008, 08:40 AM
From the flash documentation it said that interfaces should not lie inside a package.

Where does it say that?

Ayman
July 27th, 2008, 03:58 PM
ummm... well all the examples there on interfaces, don't include the package wrapping

Krilnon
July 27th, 2008, 06:09 PM
Probably this page…: http://livedocs.adobe.com/flex/3/html/04_OO_Programming_10.html

TheCanadian
July 27th, 2008, 06:36 PM
I think they're trying not to convolute the examples with code that should be inherently assumed.

senocular
July 27th, 2008, 08:26 PM
Probably this page…: http://livedocs.adobe.com/flex/3/html/04_OO_Programming_10.html

that page is indeed a little confusing because they are only showing code segments leaving out the package definitions. They do however say that "For example, the following interface, IExternalizable, is part of the flash.utils package in the Flash Player API" which implies that there is a package involved. Also it says "Interface definitions are often placed at the top level of a package" which implies that they can be placed in packages (though may not be typically). You can also scan through the interfaces in the API and see where they're defined:
http://livedocs.adobe.com/flex/3/langref/flash/display/IBitmapDrawable.html (flash.display)
http://livedocs.adobe.com/flex/3/langref/flash/events/IEventDispatcher.html (flash.events)
...and the mess of Flex interfaces available.

But, if there is any place in particular that explicitly calls out to interfaces saying explicitly that they should not be in packages, then that's an error and will need to be fixed.