FXG to MXML Graphics converter

Launch application

By now, every Flex developer should be familiar with the basics of the new Designer / Developer workflow: importing art coming from Illustrator or Photoshop into Flash Catalyst will automatically let the user convert the related graphics data into MXML skins, MXML components, and embedded assets, which will be used in our final Flex 4 application.

 

However, there are times when your workflow may require to simply copy and paste some FXG code exported from a graphic tool directly into your MXML files.

 

The problem is that you can't just do that: MXML Graphics' syntax is very close to FXG 2.0's, but subtle differences do exist. Besides the obvious necessity to add the spark namespace prefix to most tags, you may need to do a lot of housekeeping before being able to obtain a valid file. The complete list of differences between the two syntaxes is listed in Flex4's documentation, and as you can see, the amount of work necessary to do the job is far from trivial.

 

For this reason, I decided to create a small utility which would perform these tedious tasks for me, hopefully in a single pass (source code available here). There are several challenges to overcome here. One being that I wanted a very simple tool which would let the user paste the resulting code inside an MXML file, and not modify the existing MXML in any other way. The problem is that FXG files may contain various tool specific namespaces in attributes added by softwares like Adobe Illustrator. Those are only necessary in a round tripping context, ie having them in MXML Graphics won't break your code, it just won't be processed by the Flex compiler.

 

In order to avoid adding endless namespace declarations inside the MXML file's root tag, I decided to remove them all. The problem is that I do that explicitly, looking for namespaces one by one, which is really not flexible at all.

 

As a result the following flex application should be more considered as a proof of concept: you should not rely on it for production at this stage. Nevertheless, don't hesitate to send me feedback. If demand is high, I might try to improve it in order to deliver a more robust tool. Also, the idea would be to provide it as a small standalone app or Flash Builder extension, but that's another story...

Rich Rodecker (not verified) on June 10th 2010

Nice work! Was thinking about doing something similar.  One thing I think that doesn't seem to be clear (or well-known at least) is that there's nothing stopping you from using FXG files directly in Flex.  We are exporting library symbols as FXG files from Flash, and then using those files in Flex simply by doing something like: <fxg:SomeFXGSymbol />

david_deraedt on June 10th 2010

Thanks Rick. Absolutely, but this is not the same, since MXML Graphics tags behave like any MXML tag, allowing us to do things such as databinding and state-specific attributes. This is especially useful for component skins.

Renato Lima (not verified) on November 13th 2010

Congratulations!

Great work! I was thinking to write an application like this and I am glad to find that.

 

Best regards.