Well, you can't instanciate an interface, you need first a concrete class that implements the interface...

Your code should be:

interface IWorldPart {}
class SomeWorldPartSubclass implements IWorldPart  {}
var myPart:SomeWorldPartSubclass = new SomeWorldPartSubclass();
myCollection.addItem(myPart);

j.c.wichman a écrit :
Hi,
i'm using a collection, which requires items of type Object to be added.
I've declared an interface which gives me something like:
- interface IWorldPart
- a class implementing WorldPart
now somewhere else i do:
var myPart:IWorldPart = new SomeWorldPartSubclass();
myCollection.addItem (myPart);
The last statement gives a type error, if i replace the first with var
myPart:WorldPart = new ... all goes well.
From what I can remember from Java (which I admit, seems ages ago ;)), this
first should be no problem at all.
Does anyone know why this is not allowed in Flash? thanks in advance.
Hans
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to