views:

1118

answers:

2

The Flex compiler can compile "pure AS3" SWF files that don't contain any Flex Component bytecode. So,

Would it be possible to create a custom component framework (used in place of the Flex Framework), that can still be visually laid out using MXML (read: markup), and compiled down to a SWF without any dependencies on the Flex Framework itself?

+1  A: 

There are two different compilers: one that is used for compiling ActionScript code to AVM bytecode and another (mxmlc) that compiles MXML files into ActionScript code which is then in turn compiled by the first compiler. If you want to see what AS3 code is generated, pass the "-keep" parameter to the MXML compiler.

In theory it's possible to do what you suggest. My guess is that mxmlc keys heavily into features from the UIComponent class, so you'd probably have to hack on mxmlc a bit so that it didn't puke on non-UIComponent classes. Even still, since things like [Bindable] / data binding make use of Flex framework features (not plain Flash Player / AVM features) you would be rewriting an awful lot of code.

cliff.meyers
Not so. mxmlc works fine without Flex.
wulong
+6  A: 

Yes, it's possible. Your MXML files are essentially just a different way to specify classes. You can see what mxml files boil down to by compiling your project and providing -compiler.keep-generated-actionscript=true to mxmlc.

bar.mxml:

<?xml version="1.0" encoding="utf-8"?>
<flash:Sprite xmlns:flash="flash.display.*">
</flash:Sprite>

After compiling with mxmlc -compiler.keep-generated-actionscript=true bar.mxml, it turns into the following.

generated/bar-generated.as:

package {
    import flash.display.Sprite;
    // bunch of imports
    public class bar extends Sprite {
        public function bar() { super(); }
    }
}
wulong
You can shorten the compiler argument to `-keep`. Much easier to remember.
joshtynjala