+1  A: 

Okay, I'm anaswering generally, because you said, "Is this really just a phenomenon in Flex/AS3?".

In your init method, obviously you're always calling addChild with foo. That means foo must always be an instance of DisplayObject. You also want it to be an instance of IFooable (though it's not clear here why). Since DisplayObject is a class, you would consider using a subclass of DisplayObject (e.g. FooableDisplayObject), that implemented IFooable. In Java, this would the below. I'm not familiar with AS, but I think this shows there's not any general flaw in interfaces here.

interface IFooable
{
    public void runFoo();
}

class DisplayObject
{

}

abstract class FooableDisplayObject extends DisplayObject implements IFooable
{

}

class Foo extends FooableDisplayObject
{
    public void runFoo()
    {

    }
}

public void init()
{
    FooableDisplayObject foo = new Foo();
    foo.percentHeight = 100;

    addChild(foo);
}
Matthew Flaschen
Ahh, here lies an interesting point: AS3 does not have abstract classes. I'm going to update my original post with a fuller reply. Thanks for mentioning them, because I completely forgot about abstract classes. Your answer makes complete sense, but there are some issues in AS3.
bedwyr
Yes, I think you have a handle on the best way to go: Make a non-abstract base class FooableDisplayObject (or FooableVBox or whatever), and just be sure you only instantiate subclasses that correctly override the base. This should be tolerable as long as you're not exposing FooableVBox as part of a public API.
Matthew Flaschen
See also http://joshblog.net/2007/08/… for how one person implemented a run-time approximation of a abstract class.
Matthew Flaschen
+1  A: 

I think this is a place where Flex's/Flash's API is not correct. I think that addChild should take an interface not a class. However since that is not the case you have to cast it. Another option would be to monkey patch UIComponent so that it takes an interface or maybe add another method like addIChild(IUIComponent). But that's messy. So I recommend you file a bug.

James Ward
+1 for mentioning a potential bug/flaw in the API: I think many people would shy away from that. It's good to recognize shortcomings in languages, and I think this is one of them (re: Michael's response, and my latest response).
bedwyr
+1  A: 

@James Ward, That's definitely something I wish was in the language, probably a interface IDisplayObject. That would solve a lot of issues in OOP display programing in AS3.

In regards the the original question, something I've used in the past, and have seen mentioned on www.as3dp.com is to include a getDisplay():DisplayObject method in the interface, which would typically return "this" by its implementor. It's less than ideal, but works.

@Matthew Flaschen, While we don't have Abstarct Classes native to AS3, common practice is to name the class with the word Abstract ie: AbstarctMyObject, and then just treat it like the abstarct objects in Java and other languages. Our want for true abstarct classes is something the Flash player team is well aware of, and we'll likly see it in the next version of the ActionScript language.

Tyler Egeto