The day I read about Flex Code Generator (FCG) with PureMVC support it seemed as though all the hassle of setting up a new project would be taken care of with the click of a button. Turns out it might not be as great as I'd hoped.
Upon opening FCG, you're given the choice of what type of project to create: Flex, Flex + Cairngorm, Flex + PureMVC, or PHP. I have only tested for PureMVC since that's our framework of choice. It generates 4 files to start: ApplicationFacade.as, MainView.mxml, MainProxy.as, and StartUpCommand.as in a package structure with model, view, and control folders. My main gripe with these pre-generated files is that they are not editable. When they are generated you can preview the text in them; however, you cannot change any of it. Plus I would like to be able to choose the name of my view component instead of defaulting to MainView.mxml, not to mention it extends Canvas instead of Application. Also, while these are mostly necessary files, I'd like to choose whether I need a MainProxy or not. You can delete unnecessary files but the package structure for it remains. And where is the ApplicationMediator?
Along with these auto-generated files are a series of options to create an Event, Singleton, Mediator, Proxy, or to import a Value Object or Service. Somewhere along the line creating a command got left out.
Creating an Event:
When creating an event you can choose from a CairngormEvent, Event, or a custom type. FCG allows you one variable to add to the event, which you get to choose only the type. For example, if you want to make a var that is a String you get a variable called string:String, no fancy names here. This is mainly ok, variables are easily renamed. The only potential problem I see with the generation of the Event class is that FCG puts the variable in the constructor.
Creating a Singleton:
This couldn't be more straightforward. You name the class and it gives you a perfect Singleton class. You add the rest. This is probably the best and easiest part of FCG.
Creating a Mediator:
You choose the class name, FCG adds 'Mediator' to it. Also it names the viewComponent the same as the class name.
The nice part about the pre-generated mediator is that it takes care of the listNotificationInterests and handleNotification methods for you. By default all mediators are static with a static name, though this is easily fixed through manual editing.
Creating a Proxy:
Pretty straightforward, again you choose the class name and FCG adds 'Proxy' to it. That's about it other than making the class bindable and static, which again is easily fixable through manual editing.
Importing a Service:
Select a Java, PHP, or C# file to import and input your endPoint and destination and FCG will generate RemoteObject and Responder objects, then include a service call for each method in your service that you choose to import. Fairly useful if you're into RemoteObjects.
Importing a Value Object:
This is a bit touchy, it only works occasionally for me. FCG asks you to import a Java, PHP, or C# file but more often than not it doesn't register anything in the file. Once you find a file that works, get ready for a load of new files. FCG generates the VO with optional getters/setters for each var, and a Proxy in which it includes an arrayCollection and a reference to the VO. Optionally you can generate an Event class that will include GET, GET_ALL, CREATE, UPDATE, DELETE, and SELECT events, as well as two view components, a form and a list, and their corresponding Mediators.
This is where it gets a bit confusing. For the list view it generates a list with a create and a delete button, and a mediator that listens for an item added, deleted, or selected from the list. For the form it is a textInput with a save button that will rename the selected item in the list. Although I can see the use of creating a view and its corresponding Mediator, the addition of ui components to the view class is a bit unnecessary.
The biggest change that would make me more likely to use FCG would be the ability to edit the text in the generated classes before publishing. Overall, I would recommend FCG for creating instances of certain files that are annoying to create over and over, but not an entire setup. FCG's most convenient feature is that it allows you to publish only selected files from the generated project as opposed to the entire set. Any one out there saving time with FCG?
5 Comments
Lauren-
I’ve been using FCG for my Cairngorm work for the last few weeks…although, I don’t use it for 100% of my work. I love it because it generates a ton of boiler plate code for me when I’m starting a new use case or piece of functionality. Ultimately, I take the code and refine it to my needs, but it beats the heck out of writing all of that code from scratch!!
FYI – You can edit the code generation templates for each component….for me, those templates reside on my mac in /useraccount/Library/Preferences/FCG.****/Local Store/FCGTemplates
Ryan
Ryan,
Thanks for the tip about the templates. That might help a bit though I would still prefer to edit the text in FCG before publishing so I can add any variables or methods I might want to stick in there.
I also noticed in my template folder that there is a template for a command file, yet no way of creating a command in FCG. Strange?
cool site , thanks
Hi Lauren,
Looks like I’ve stumbled upon this post a little late!
First, thank you very much for taking the time to write about FCG.
I’m sorry you felt disapointed by it though, so I’ll try to explain one or two things here.
My main point is that I understand your frustration, and so I invite you to download the source code and just make your own features. I can’t do that much by my own, especially on a free software.
Now, concerning the problems you’ve encountered :
-I’ve pulled out the live editing feature (yes, it was there in the first versions) because it caused some generation problems and FCG is not a code editor, just a generator.
-like Ryan said, it looks like you missed your code templates, in your user preferences folder.
- You can’t change the default names, but it can be refactored very easily.
-The MainView does not extend Application for a reason : the code FCG generates should be portable. You can use it in Flex, AIR, or for modules. This is considered good practice not to put any framework implementation in your root MXML file.
However, these are not excuses. Some things are wrong, and you have the right to ask for more. I realize FCG could be far better. Many features you want are already implemented in FGL, but not in FCG. For example, the ability to create a MainProxy, Mediators, and Commands. So you should be able to use it quite easily.
Regards,