Flex2 :: MXML component vs AS component
Hello,
There is such a thing as change and the spring time reminds me most of this energy. At on time, my programming skill relative to Flash was that of hard core AS classes that I never really thought of using an XML and AS combo. Well, in my mind things have changed.
What has changed in my mind? Flex Builder2 is a very powerful visual development tool for me. This has allowed my programming and development skills to reach new levels on an inspiration and engineering level. When I first got into making components, I took the old Flash8 approach and designed them in pure AS. As I started creating more components, the more complicated the UI became and as a result my classes began to look like new() this and addChild() that.
The crossroads;
I started investigating the use of MXML components and suddenly realized that wow, if I keep the view mechanics inside the MXML and also created my class overrides in the MXML file, my workflow suddenly increased 10 fold! This was because Flex2 has such a powerful child management algorithm that I was essentially recreating the wheel with using new() and addChild().
I was never a C++ programmer so the include directive is not in the scope of my programming idiom. I will never use include in an MXML component. You may ask my reasoning for this approach.
The more I read about encapsulation, OOP, patterns and the actual theory of Object design, I find myself justifying my approach(at least to me).
When a component (module) is written it should only have ONE duty. This duty should be clearly evident in the actual implementation of the class itself. This achieves two things right of the bat for me.
1) Your code becomes self documenting.
2) Your class becomes smaller.
With these two facts, I am able to without a doubt create an MXML component that is a as beautiful the sun rising on a clear day. So in effect I actually motivate myself to create a single minded component that uses as little logic to perform it’s duty and can see my UI logic at the same time! What better way to see these two things together but with MXML representation of the UI and the beautiful logic held atop it in the tag with pretty little overrides and your extended behavior right there.
Now, I am not saying that the include does not have it’s place. I am merely speaking of the component (module) development. I could see when you are creating applications this might actually be useful. Although you will never see me use an include statement unless my client prescribes it so.
Where do pure AS components fit into this theory? When you want to create something that is truly individual from the super class’s UI, this is when you need to use AS. As I get more into these types of components I will talk more about this.
One good example of this is my TEOTaskList and TEOTaskPane components. These components have so much extra and extended logic that is purely dynamic based on runtime variables; we need AS classes to nail down it’s own algorithm.
The moral of the story, MXML components are awesome, AS components are even better but, use them with caution.
Peace, Mike