Flash and Flex APIs Lack in Quality
Coming from long term Java programming, I can see that I have gotten used to very good api design. It is not, that JavaSE and JavaEE doesn’t have their corners of bad api design. But working with flash and flex, I seem to come across strange and bad api design a bit too often.
The other day, I noticed that the flash.events.ErrorEvent actually inherits from flash.events.TextEvent. What the f*** happened there? I guess this is an prime example of using inheritance as a means to reuse, instead of as a means to express some static, is-a relationship in a model.
To see what I mean, read the documentation for the TextEvent class:
An object dispatches a TextEvent object when a user enters text in a text field or clicks a hyperlink in an HTML-enabled text field. There are two types of text events: TextEvent.LINK and TextEvent.TEXT_INPUT.
Okay then, a TextEvent is something about a user, that has done something in a UI, that has produced some text, which the application shall know about. Now, let us take a look at the documentation for the ErrorEvent class:
An object dispatches an ErrorEvent object when an error causes a network operation to fail. There is only one type of error event: ErrorEvent.ERROR.
That is a completely different thing than a TextEvent. There is no chance, that saying “An ErrorEvent is also a TextEvent” could be true.
September 11, 2008
Tags: as3, flash, flex Posted in: Design, Programming

10 Responses
That’s interesting. I wonder what the thought process was behind that decision.
Yeah, that’s a total WTF, agreed. But I’d reserve judgement until you’ve examined the Flash 10/Flex 4 APIs in detail. Some legacy stuff is bound to creep in, but by and large the APIs have improved with each iteration after FP9/Fx2.
On a related note, have you seen the AS2 API? Now that was a fraked API… and until the last few years it’s all Flash Platform Developers had to work with.
Personally, I’d log the “ErrorEvent inheriting from TextEvent” as a Flash Player API bug with Adobe JIRA.
Well, events are generic and can be used for any situations. ErrorEvent extends TextEvent just because of “text” property. So ErrorEvent does not add other functionality than deriving from TextEvent and switching the object name to ErrorEvent to be more meaningful for developers. TextEvent is used solemnly in Flash framework in text components like Text.
But if you take a look, DataEvent and TextEvent are same, and DataEvent.data and TextEvent.text are strings, so TextEvent, DataEvent and ErrorEvent can be happily used in any situation for an object which needs to transport additional string value
The better way would be Event to have a string property (text, value, data or whatever name) and then all these 3 could go.
And if Event would have an additional “data” property of type Object then things might be even more generalized and less strict.
Every language and framework has its quirks and Actionscript 3.0 is no exception.
I am quite a neophite in programming, but slowly developing a passion for it along with my skills. I am using AS3 and flex primarely now (kind of taking my distances from Javascript, still love PHP). Thank you for offering a critical view informed by your experience. It helps less knowledgeable persons like me step back and try to get more of the big picture. That said, I am sticking to FLEX or Flash AS3.
Thanks.
Just out of curiousity, have you tried looking at Silverlight? Personally, the beginning of my career was heavily focused on JavaSE and JavaEE. I peaked at Flash but I had similar frustrations with the APIs. Later (about 6 years ago), I took my Java skills and easily picked up .NET. Then, almost 2 years ago, I began running with Silverlight. I have not looked at JavaFX so I cannot comment on it. However, if you are a Java developer looking for a RIA framework, I would definately recommend taking a peak at Silverlight.
@chad: I have only but taken the slightest peak. I *have* worked with .Net and Visual Studio using ASP .Net though. That experience made me really scared for toolchain lockin. Visual Studio alone could keep me away from Silverlight.
And what about java collections?
Why adding method of any Collection called .add, and adding method of Map called .put? and so on…Every technology has “bugs”…and it is OK…You get used to it, or switch technology.
Link Post Sunday 09/13 | Mr Sun Studios - September 14, 2008
[...] Flash and Flex APIs Lack in Quality and Are AS3 Number Variables Objects or Not? by Tech Per [...]
Stg: map uses put because it doesn’t always add a value (if the key already exists it changes a old value).
@Dimitar DataEvent and TextEvent are conceputaully different…
imho two classes who just so happen to have two properties of the same type are not identical…
i think great api design should be conceptually obvious and it is really important to maintain that voice of communication to the programmer even if two events carry the exact same data types they communicate differnt ideas…
Leave a Reply