You can't do that easily. The Flex components communicate with eachother for many things such as measurement, layout, focus management etc. You would have to extend your Sprite to do all the stuff the framework normally does.
You don't have to use MXML though. You can also write purely AS3 Flex projects. But the starting point will still be one of the Flex base classes.
I could create my own elements using AS3, but it would be nice if I didn't have to and I could utilize some of the Flex components that are already prebuilt and are pretty great. (I would hope that this is made possible when the Flex Open Source movement gets into full swing.)
Is there another way of doing this? Could I use some kind of general UIComponent instead of a Sprite and then add other UIComponents like TextInput to the main UIComponent? But then how do I add the main UIComponent to the stage?
So the code would look something like:
var main:UIComponent = new UIComponent();
var input:TextInput = new TextInput();
input.width = 100;
input.height = 50;
input.text = "Hello World";
main.addChild(input); //OR main.addElement(input);
Basically I want to reduce the need to use MXML. (If I need to create one main MXML class, then that's probably fine.) I want to be able to use Flex components in pure AS3.Is there a strategy to do this?
There is a lot of bootstrapping when the compiler generates code for MXML that is used by UIComponent. If you don’t use it, you will have to use a lot of glue. Really small AS3 apps should not be using Flex components.
If you want to use UIComponent and just want to avoid using MXML, the easiest way is to just have an empty MXML application and use the preinitialize event to start running all of your actionscript.
You can also use –keep-generated-actionscript to see the AS generated by MXML and stitch it all back together. It is a real pain though, and if you make certain kinds of changes you will need to re-stitch everything all over again.