Recently I decided to consolidate all of the custom and reusable controls I had created in Flex into a single library. Even as good as Eclipse is at refactoring (one of the things it actually does well) it still wasn’t was clear cut of a procedure as I had hoped for.
Step 1: Create the library
everything in Flash Builder 4, creating a new library is just a matter
of right-clicking somewhere and selecting New and then “Flex Library
Give the library a name and you are good to go. One caveat though. If you look closely, you will see a check box “Include Adobe AIR libraries” If your components will need access to things like flash.filesystem.* you will need to check this box. NOTE: I have yet to test a library with AIR libraries included inside a Flash application, most of my programming is AIR based. I do think it should work. However, if it does not, you will need to break your libraries into AIR and Flash respectively.If you forget to check the AIR libraries box or if you change your mind later, you can right click on the project, select properties and then “Flex Library Compiler”.
Step 2:Migrating Components
For most of my components, this was as easy as dragging them from the project they were in into the new library. Since one of my components (My File Selector control) required access to the file system and I had NOT checked the AIR libraries check box, it did not come over without errors. It took me a while to realize the error because Flash Builder was giving me the very helpful “Unknown Flex Problem” error. By the time I realized what the problem was, I had re-created the entire class manually. (Not a terribly difficult process for this particular control) Re-creating it also gave me a chance to refactor it and split the code and MXML into separate classes.
Step 3: Use it!
The final step is to link the project to your new
library. Just right click on your project, select properties and then
“Flex Build Path”
Click on “Add Project” and Flash Builder 4 will give you a list of all the libraries it knows of that you have not yet included in the project. Select your new project and click on OK.
That was all there was. Other than the one snag, it was a very easy process. Now I just need to locate and migrate the other little controls that I have written into this library.
Until next time,
I <3 |<