FXG paths to Flex components convertor
While working on a project yesterday I needed to convert several vectors (hundreds of them) into reusable Flex 4 visual elements that I could then use in my skins, so lets say if I have vectors of chess pieces that I would like to use in my Skin as follows …

Since I needed these in several skin files I did not want to deal with clunky Path elements which would’ve looked something like this..

So I created a quick AIR application …. that that converts the elements into AS3 classes that extend from spark.primitives.Path and look something like this …

This way all my path data sits in one place I can use this library of visual elements in a reusable way across several applications and changing something would be really easy. Also, unlike the generated code from Flash Catalyst (Thermo) all my components are not inside Groups which are fairly heavy components.
Watch this quick video of a detailed demo of how to use the tool …
If you think this is something useful for you to ….
Download and Install
Since I did this in very little time the code is quick and dirty but it works and is available under the Apache 2.0 License on Google Code so feel free to to modify for your own needs.
View Source at Google Code
An after thought was that this should probably not be called FXG to Component since the generated classes do not inherit from UIComponent but instead from Path which is a GraphicElement. Anyways, who cares as long as it does what its supposed to do.
Please do let me know if you find this useful.









May 8th, 2009
Nice! welcome to join the club for code generation:) RT @mrinal: [New Blog Post] FXG paths to Flex components converter http://bit.ly/9Mcd2
May 8th, 2009
RT @ArulKumaran RT @mrinal: [New Blog Post] FXG paths to Flex components converter http://bit.ly/9Mcd2
May 8th, 2009
RT @davidderaedt: RT @ArulKumaran RT @mrinal: [New Blog Post] FXG paths to Flex components converter http://bit.ly/9Mcd2
May 8th, 2009
RT @mrinal: [New Blog Post] FXG paths to Flex components converter http://bit.ly/9Mcd2 – very cool!
May 8th, 2009
really useful little AIR app by @mrinal – wish I had more time to play with Gumbo — http://bit.ly/9Mcd2
May 8th, 2009
really useful little AIR app by @mrinal – wish I had more time to play with Gumbo — http://bit.ly/9Mcd2
May 8th, 2009
really useful little AIR app by @mrinal – wish I had more time to play with Gumbo — http://bit.ly/9Mcd2 (via @peterelst)
May 8th, 2009
Convert FXG to Flex components w/ really useful little AIR app by @mrinal – http://bit.ly/9Mcd2 (RT @peterelst)
May 8th, 2009
Hi Mrinal, this is an interesting approach but note if your vector never changes at runtime it would be better to take advantage of FXG at compile time in Flex.
In the latest Flex 4 builds, it still sees .fxg files as custom components but it now treats .fxg files as static vector assets and compiles them into SWF graphics primitives instead of ActionScript Byte Code. This results in an enormous reduction in memory and startup time because the player does not need to create all of those object instances in ActionScript to do the drawing.
May 8th, 2009
Hi Pete,
Thanks, I did not realize that you can use a .fxg file (lets say KING.fxg) and then refer to it as a component in mxml ..
That is very cool !
Although, that does not give me what I wanted … since that vector can no longer have parameters .. like fill, stoke etc that I would like to change .. in some cases even control from my controller (component whose skin has this asset)
That said, I think it will be a valuable feature addition to the generator to able to break down a huge FXG with several paths into a .fxg for each path … should be easy to do.
What do you think?
Mrinal
May 8th, 2009
Very cool idea Mrinal! I like it. As Pete said, if you’ve got an FXG file that won’t change it’s probably better to treat it as a static asset. I’m hoping to do some test on that when I get back from vacation.
I’m not sure how breaking down an FXG file into smaller parts would work but it’s an interesting idea. If you do the testing let us know.
=Ryan
ryan@adobe.com
August 7th, 2009
Hey Mrinal,
great idea. But i´ve noticed a little Bug. I have a Path with a huge amount of data und in the generated .as the data string goes over multiple lines. The compiler doesn´t like that. I´ve found a solution for that from Doug McCune: http://dougmccune.com/blog/2007/05/15/multi-line-strings-in-actionscript-3/
Maybe that should be wrapped around the data string. Works in my case.
Greets Jan
August 18th, 2009
Hi Jan,
That seems like a good idea … I will try and change that whenever I have some time. If you wish I would be glad to make you a committer on the google code project and you can make the change your self.
Thanks,
Mrinal
September 2nd, 2009
Hi Mrinal, how are you?
Hope that you are well
Very cool generator, just what I was looking for. Any developments on some of the ideas that have been mentioned above?
Maybe I should first check the google code page to look for any updates so that I don’t look like a dummy, but would be very interesting to see some of the above achieved.
Very nice work though, VERY COOL STUFF!!
Thanks