A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Designing an interface for a display object

  1. #1
    Multitouch Aficionado
    Join Date
    Mar 2006
    Posts
    275

    Designing an interface for a display object

    I'm working on a series of classes that each distort an input image using a series of parameters. Each class is a Sprite that contains the distorted version of the input image.

    I have the parameters defined in an interface that I plan to implement in each class. How can I include in the interface the fact that each implementation should extend Sprite?

    I suppose that I could use a getter that returns a Sprite, but it would be nice if the classes themselves could be added to the display list.

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Someone please correct me if I'm wrong - but I don't believe you can implement display objects at the interface level (as there isn't any ISprite or IMovieClip to invoke)...instead just lay out your interface as a standalone, and then have each of your child classes implement the interface and also extend sprite:

    public final class Distortion1 extends Sprite implements IDistortion{ ... }

  3. #3
    Multitouch Aficionado
    Join Date
    Mar 2006
    Posts
    275
    Thanks.

    That's what I have. The problem is that I end up doing addChild(_distortion as Distortion1) which is less flexible than ideal.

    Maybe I'll add function get displayObject()isplayObject to the interface.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Perhaps an abstract class is more what you need. You could have a class which extends Sprite which declares the methods you need (or even implements the existing interface you have), but all those methods are simply empty stubs. Then you can extend that class with actual useful subclasses which override the stubs.

  5. #5
    Multitouch Aficionado
    Join Date
    Mar 2006
    Posts
    275
    Yeah, I had considered that too. It seemed sloppier than an interface though, because then you need to override everything.

    There are definitely workarounds, but it seems like this ought to be pretty straightforward.

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I agree, it would be nice if DisplayObject.addChild took an interface rather than DisplayObject, or if there was a way to add extra type information to an interface like you ideally want. Or even a proper "abstract" keyword. Oh well. It's an evolving language.

    I think a true abstract class would fit your needs pretty well, but we can only simulate abstracts at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center