Hi,

I've had the same problem and couldn't find a real solution.

The simplest thing to do, for me, was just using the as operator:

var obj:ISomeInterface = new ConcreteObject();

container.addChild(obj as DisplayObject);

I like that it doesn't require an extra variable and it doesn't clutter your
code too badly.

The only real solution, I think, it's on Adobe's hands, since DisplayObject
is a concrete class defined natively by the player (well, sort of, at
runtime it behaves like an abstract class since you can't create an instance
with new ...).

The cool part is that the change should be simple and backward compatible.
Just provide an IDisplayObject interface and have DisplayObject implent it.
Then change method signatures in the dispay list API to require
IDisplayObject instead of DisplayObject. In your code, your interface can
extend IDisplayObject, and that should solve the problem:

interface ISomeInterface extends IDisplayObject

class ConcreteObject extends Sprite implements ISomeInterface

The bad part, as I said, is that only Adobe can fix this.

So, until that happens (if it happens someday...), I just do a cast to
DisplayObject on the argument at call time and carry on.

Cheers
Juan Pablo Califano



2009/8/7 Tom Huynen <[email protected]>

> Hi!
>
> I have a tiny little problem with the following:
>
> I have two classes that should have the same dataType in order to use them
> in a third class. So I created an Interface that both of them implement.
> The two classes extend Sprite because they have a visual representation.
> However, when I try to add them to the displayList flash doesn't recognise
> them as a displayObject.
> I read that many people at this moment cast them back to a displayObject
> but
> that to me feels like a workaround.
>
> Anybody any suggestions?
>
> Thanks!
>
> Tom
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to