Base Interfaces - Good practice?
Do you guys think this is good practice? I made an interface called IOverlay and I could not set the mouseChildren property, etc. So I made these interfaces, now I'm using them everywhere! I find them really useful.
- flash-interfaces.zip 3.4 KB
- IDisplayObject.as 4.1 KB
- IDisplayObjectContainer.as 1.3 KB
- IInteractiveObject.as 2.5 KB
- IMovieClip.as 1.1 KB
- ISprite.as 829 Bytes
Comments are currently closed for this discussion. You can start a new one.
2 Posted by rob on 28 Mar, 2010 07:45 AM
Thanks for taking the time to do this Matan. I personally don't believe it's a bad practice as I feel like typing to interfaces is a good thing. A friend and I were just discussing this very same issue and he pointed me to this thread. I think that Adobe is actually guilty of bad practices by not having MORE interfaces in the core classes. There are only 11 interfaces in the core and none of them directly relate to the display list. Checkout this post by Jesse Freeman on the matter: http://flashartofwar.com/2009/08/13/what-the-interface/
Unfortunately, as he points out, if you're typing to these interfaces you'll be forced to cast in instances where you have to addChild. Like stage.addChild(myIMovieClip as DisplayObject); Right there is a perfect example of why Adobe needs to implement better interfaces.
3 Posted by Matan Uberstein on 28 Mar, 2010 10:52 AM
I believe that casting when adding or removing from the stage is a small sacrifice at this point, but I do agree with you that Adobe needs to use more interfaces. I think if they need switch over to display object interfaces, they'll need to write a 3rd vm inside the player. I don't see that happening soon.
They must have realized this short coming themselves, take ICellRenderer for the List component, at some point they need to add those instances to the display list, so they must be casting to DisplayObject.
If an instance is begin added and removed constantly, I like added a getter
asDisplayObject, when this instance is constructed I do the cast once and store it into a protected var. Then when I need to add or remove this instance I refer tosomeInstance.asDisplayObject. I'm sure this must save some processing.Thanks for the response Rob. :-)
4 Posted by Sprog :: Weyert de Boer on 29 Mar, 2010 02:37 PM
Thanks for creating those interface makes life a lot easier. I prefer to use the interfaces instead of continuously casting the object into a DisplayObject.
Somehow the use of interfaces gives me more a feeling it's all nicely strong typed without the need of wrappers.
5 Posted by Matan Uberstein on 29 Mar, 2010 02:44 PM
No problem! I Glad you can use them! :-)
There are still a lot more I want to create, but those are the common ones.
6 Posted by rob on 29 Mar, 2010 03:42 PM
@Sprog
Per your comment: "I prefer to use the interfaces instead of continuously casting the object into a DisplayObject."
If you type to any of these interfaces you will have to cast to a DisplayObject for certain actions such as addChild because they expect an object of type DisplayObject not IDisplayObject.
Just wanted to clarify that before you ran into it and thought "What's going on???"
7 Posted by Sprog on 29 Mar, 2010 04:09 PM
Yes, I am aware you still need to cast it... but not when you want to change some properties on the display object instance. prize.x = 0 is much nicer then DisplayObject(prize).x = 0.
Stray closed this discussion on 11 Feb, 2011 11:36 PM.