Creating SWCs using Flex 2 Builder


With the recent release of Cairngorm 2 Alpha 2 from the guys over at Adobe Consulting i decided to compile Cairngorm 2 into a SWC file using Flex 2 Builder. This is similiar to .NET in that you can create class libraries and compile them into .NET assemblies (dll files).

The steps i took to accomplish this task were as follows…

Select Flex Library Project

Select File –> New –> Flex Library Project which should look like the above.

New Flex Library Project

Next step is to enter your project name and path to the location of the AS3 files. Once you have done that press next.

Flex Library Project Build Paths

The next screen should be the build paths with tabs four tabs called Classes, Resources, Class path and libraries. The on we are interested in is the Classes tab. As you can see above i have selected all the files which i want to be compiled into a SWC file. You do the same and then when you are done press finish.

If all goes well you should see a [project_name].swc in the bin directory of your Flex Library Project. The last step is to add it as a library to your project.

Project Properties Build Paths

To do this you need to have one of your project files open in Flex 2 Builder. Select Project –> Properties and then Flex Build Path on the left. You should then see something resembling the above image. Select the Libraries tab and then press on Add SWC…, locate the SWC file that you have just compiled. It will be added to the bottom of the list. Press OK and Flex 2 Builder will now include this library in your project.

To test if the library is working properly type import [package] (e.g. import org.nevis.cairngorm.model.ModelLocator;) and save your project, if there are no errors then perfecto everything works.

This feature rocks!!!!

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Other Posts
Flash Player 8 - Native Version for the new Mac Intel machines?
Using the BlurFilter in Flex 1.5 from Jesse Warden

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Glad you like this feature! This is a great explanation of how to create a SWC. One minor correction though- resource bundle SWCs refers to SWCs used for localization. These are SWCs used with the new resource bundle feature in the beta. Other SWCs, like the one you created, are just referred to as SWCs.

Flex 2 really does make SWC creation easier than ever. Neat run-through ;)

I set a library up yesterday and no SWC was created.

After giving up, shutting down and restarting today i now see the SWC.

Problem is i’ve now edited my library, add classes to it, and delete the original SWC. Any idea how i can force it to re-compile the SWC with the new classes included?

I’ve got in the properties of the Flex Library and selected all the new classes under ‘Flex Library Build Path’ and clicked ‘ok’, but no SWC is outputed. I can’t great a configuration to run it as its only a library, and if i run it as a Flex App i get an error saying it can’t find the html.

Any help appreciated

ahemm blushes slightly

i believe it was because my library had errors

Hi

I have created a flex project and i want the classes i created need to be bundled in swc. For this i follwed the step given above but not able to create swc.

Uptill 2nd step it is working fine but on third step where classes, resource, class path,libares tab comes.In classes tab my project is not showing any AS files which i have to bundle in swc.

Can any one help me out how to overcome this.

Thanks in advance,
Parag