# Common interface for classes that extend sprite

**URL:** https://forum.kirupa.com/t/common-interface-for-classes-that-extend-sprite/276190
**Category:** Uncategorized
**Created:** [November 24, 2008, 10:54am UTC](https://forum.kirupa.com/t/common-interface-for-classes-that-extend-sprite/276190 "2008-11-24T10:54:19Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![watcher](https://avatars.discourse-cdn.com/v4/letter/w/77aa72/32.png) [@watcher](https://forum.kirupa.com/u/watcher)
#### Post date: [November 24, 2008, 10:54am UTC](https://forum.kirupa.com/t/common-interface-for-classes-that-extend-sprite/276190/1 "2008-11-24T10:54:19Z")

</div>

Hei!

Im trying to implement an interface for custom classes that extend Sprite (DisplayObject), but i can’t use DO methods on those instances afterwards, when called via the interface… illustration:

```auto

**interface** :
public interface IListingItem extends IEventDispatcher
 {
  function setData( someData ):void;
 }
 
 
// **usage**..
var instance:IListingItem = new MyDisplayObject( ); // **MyDisplayObject extends Sprite, implements IListingItem**
    instance.addEventListener( Event.COMPLETE, onItemLoaded ); // okay, since interface extends IEventDispatcher
    instance.setData( "bla" ); // still okay, since interface defines this method
    instance.x = 10; // [COLOR=red]1119: Access of possibly undefined property x through a reference with static type classes.interfaces:IListingItem.[/COLOR]
this.addChild( instance ); // i guess this would also throw error

```

So maybe i do something wrong? Should be interface only used for calling some simple methods that don’t work with display list?  
Initially i also got an error calling that addEventListener on the content instance, that disappeared after i told the interface to extend IEventDispatcher. Is there similiar interface that defines DO properties like ISprite or something? Or should this technique not be used at all? Any ideas welcome!

Thanks design-patterns-flash-gurus!
