True Genealogy of Flex TextInput and TextArea
Prologue
From Adobe Flex API reference, http://livedocs.adobe.com/flex/201/langref/, you may find that the hierarchical relationship on TextInput and TextArea is like below:
- TextInput -> UIComponent
- TextArea -> ScrollControlBase -> UIComponent
What does this imply at the first sight? To me, it means TextInput and TextArea inherit something from UIComponent. Yes, they do, but what do they inherit? My curiosity here are:
- how these very familiar text-based component do not inherit a text-related abstract class, but a generic UI class; and
- whether they have anything to do with flash.text.Field
I cannot find out the answer from any reference documents, so, unfortunately, I have to look into the open source code, which is fortunate. In the source, I met another guy, mx.core.UITextField, the child of mx.core.FlexTextField, the child of flash.text.TextField. So the legend starts here.
Chapter 1
Once upon a time, flash.text.TextField, who existed back to the age of ActionScript 2. (By the way, FYI, now it is ActionScript 3 Era) Mr TextField was a functional worker to build the text field in Flash Player as same usability as the text field in the OS-native programs.
Then time went on, capitalism came, the value system of labor has been changed. It is not about what you can do, but how you present your output. Functionality is good, but the architecture and usability are better. There are milestones for the new era: ActionScript 3, Flash Player 9, and Flex 2.
Since the new management is on board, he changes the architecture of hierarchy from developers’ perspective. The new arch is more and more like to other framework: Java Swing, and .Net Forms. Never mind. And the new management wants to reuse the effect of veteran Mr TextField. So the decisions has been made like this:
- Bringing TextField’s talent into Flex subsidiary company, by hiring TextField’s descendants. FlexTextField, the immediate child of TextField, really does not do so much but rename toString(). UITextField, the grandchild of TextField, is a real reformer, who does not only follow the compliance of Flex policy but also does a lot of preparation to work with his two immediate bosses.
- Hiring two account managers, named TextInput and TextArea. Sounds familiar? They basically knows nothing about how Mr UITextField does the dirty work to make text field appears on Flash Player. They represents UITextField to the customers, that are Flex developers.
OK. Hope you got the idea.
Chapter 2
One last question: can Flex developers access Mr UITextField in one way or another? The answer is yes. There are two ways to do that.
Way One: If you make a customized TextInput or TextArea by extending them, you can have an access to protected variable of UITextField, named “textField”. Of course, before that, you have to ask yourself whether you really mean to extend one of these 2 classes.
Way Two: Have you heard of mx_internal? If you knew him, you probably have gotten the idea, and the tip is that there is “mx_internal function getTextField():UITextField” in each of TextInput and TextArea. If you have not known mx_internal, allow my verbosity.
You know, you cannot access the internal property of another company. The UITextField is intent to be an internal property of Flex, officially. It is good for you, since the details of possibly unnecessary complexity has been undisclosed; It is bad for you, if your creativity exceeds Adobe’s imagination. However, Adobe is Adobe, not another giant. Adobe opens the source code, and opens the backdoors for you to access UITextField. For the class member labelled with mx_internal you can access it with a tiny extra effort:
- import mx.core.mx_internal;
- use namespace mx_internal; textAreId.getTextField();
- textAreaId.mx_internal::getTextField(); // textAreaId refers to an instance of TextArea, for example
For more information on mx_internal, read Daniel’s blog: http://life.neophi.com/danielr/2007/05/mx_internal.html
Epilogue
Now you should know, who is the real hero to display text-related component on Flash Player, and how to communicate with him directly.
Note: No offense on capitalism, account managers or Adobe!