Skip to content

Migrating Flex components to Flex Libraries

Dear Reader,

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

As with everything in Flash Builder 4, creating a new library is just a matter of right-clicking somewhere and selecting New and then “Flex Library Project”.

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 |<
=C=

2 thoughts on “Migrating Flex components to Flex Libraries

  1. Buenas!

    Podrias comentar como solucionaste el “Problema desconocido”?

    Verás, tengo una aplicacion web en Flex 4 que carga de una libreria una serie de componentes.
    En la aplicacion tengo un mxml que carga las vistas, que estan en la libreria, en una tabBar.
    En la libreria tengo varias vistas, clases, asi como demas componentes que uso dentro de estas vistas.
    Resulta que llevo unos días que me sale un “Unknown Error” en la libreria y no se de que puede ser.
    Grácias por la ayuda de antemano.

    Saludos

  2. Sorry for the first comment, it’s in spanish, and sorry in advanced for my english.

    Could you explain how you solved the “unknown error”?
    I have an aplicattion that loads from a library a several components. Many days ago, Flex show me that error and I don’t know where is the problem and what to do to solve it.

    Any help would be apreciated,
    thanks!

Comments are closed.