In case your custom Form and Panel components share same method names (with different functionality), you can create an Interface with the common methods declaration and have both components implement it.
This way you can declare the new interface as the returned type and invoke the common methods that it have.
Thia is sort of a Polymorphism technic, a subject where you can read more about in the following page -
I thought about using interface, but it caused other problems, for example, the object can not be used in method as the type.
My original question was that if I defined a variable w/o using any types, I only get a warning and it seems that object
can be used for anything. What is the terminology for this type of object in OO?
I came from a Java background, it is not possible in Java. I would say ActionScript is not a very strong typed language.
That's right, AS is not as strongly-typed as Java, which gives you more
rope, which you can sometimes use to hang yourself.
Interfaces are the recommended way, you might have to cast when passing
Here is the problem:
I need to add a View Object in ViewStack using addChild method that requires a type of DisplayObject as the parameter.
My View Object could be a Panel or a Form and has several custom methods defined as Flex mxml file.
I put the custom methods in an Interface (IMyInterface) and my View Object implements the Interface.
If I use IMyInterface as the type for the View Object, I could not add it in the mx:ViewStack as addChild requires DisplayObject. It looks like
the only solution is that using the generic object without type (with warning). The IMyInterface does not help me here. It seems that dynamic polymorphism
does not apply well with Flex/AS.
If you have
Then you should be able to do:
I'm pretty sure I suggested casting in the last reply.