In the past, if you wanted to create a SWC library from your ActionScript classes you either had to use FlexBuilder or the Flash IDE. After Adobe open-sourced the Flex SDK you were also able to use the command line tool compc.exe at no extra cost. But if you don’t like to mess around with command line tools you have another option now. A developer from Sydney released a SWC export plugin for the popular open-source ActionScript development environment FlashDevelop. The plugin is based on compc.exe but it hides all the ugly details from you.
This tutorial will guide you through the steps of creating a simple ActionScript component and compilling it into a SWC file.
Installing the SWC Export Plugin
The plugin installation is a piece of cake. Download the plugin from here, unzip the ExportSWC.dll file and place it in FlashDevelop’s Plugin folder. (If you don’t know where to find this folder go to the “Tools” menu and click on “Application Files…”.) After restarting FlashDevelop you should see a new icon in the toolbar:
![]()
Sample Project: A Status Component
You will be creating a simple status component as a sample project. It displays different icons according to the status set. As for the icons, I’m using two icons from the free “Silk” icon set which can be found on www.famfamfam.com:
![]()
The first icon is supposed to represent an “OK” status, and the other one signals an “Error” status. (For example, you could use this component as an item renderer in a Flex DataGrid for displaying the status of the listed items.)
Setting up the FlashDevelop Project
Create a new project in FlashDevelop and select “ActionScript 3 / Default Project” as template. Call the project “StatusComponent” and save it. If you look at the project panel you will notice that FlashDevelop has already created two folders (bin and src) and a class file (Main.as) for you. Please make sure that the src folder is the only folder in your classpaths settings:

Now follow these steps:
- Create a third folder on the same level as the bin and src folders and call it assets.
- Copy the two icon files into this new folder.
- Under the src directory create a hierarchy of three sub directories: com/log2e/components. (I’m using my domain name here, you can name them whatever you like, of course. But it’s considered good practice to organize your class packages with the help of unique names such as domain names.)
- Finally, move the class file Main.as into the components folder and rename the file to StatusComponent.as.
Your project panel should look like this now:

Now open the StatusComponet.as file.
The ActionScript Code
I’m posting the complete class code first, and then I will go through the code step by step.
-
package com.log2e.components
-
{
-
import flash.display.Sprite;
-
import flash.display.Bitmap;
-
-
public class StatusComponent extends Sprite
-
{
-
public static const STATUS_UNSET:String = "status_unset";
-
public static const STATUS_OK:String = "status_ok";
-
public static const STATUS_ERROR:String = "status_error";
-
-
[Embed(source="../../../../assets/accept.png")]
-
private static var iconOK:Class;
-
[Embed(source="../../../../assets/exclamation.png")]
-
private static var iconError:Class;
-
-
private var _status:String;
-
private var _statusIcon:Bitmap;
-
-
public function StatusComponent()
-
{
-
_status = STATUS_UNSET;
-
}
-
-
public function get status():String
-
{
-
return _status;
-
}
-
-
public function set status( status:String ):void
-
{
-
_status = status;
-
-
if (_statusIcon)
-
{
-
removeChild(_statusIcon);
-
}
-
-
switch(_status)
-
{
-
case STATUS_OK:
-
_statusIcon = new iconOK();
-
addChild(_statusIcon);
-
break;
-
case STATUS_ERROR:
-
_statusIcon = new iconError();
-
addChild(_statusIcon);
-
break;
-
}
-
}
-
}
-
-
}
Line 1: The package definition reflects the directory structure we created below the src folder.
Lines 3-4: We only need Sprite and Bitmap as display objects.
Line 6: Since we are creating a visual component the StatusComponent class extends Sprite.
Lines 8-10: The three constants hold the status definitions as strings. They are accessible from outside the component (for example, StatusComponent.STATUS_OK).
Lines 12-15: The two [Embed] metadata tags include the two icons in the SWF and SWC files at compile-time. Instances of the embedded assets can be created by the standard new syntax.
Lines 17-18: The two private variables hold the current status information and the displayed icon.
Lines 20-22: When a new instance of the component is created the constructor sets the initial status to unset.
Lines 25-28: The getter method for the status property.
Lines 30-50: The setter method for the status property. This method not only updates the private _status property, but also removes the currently displayed icon from the display list and instantiates a new icon according to the status set.
Exporting the SWC File
All the hard work is done. The SWC file is only a mouse click away. Of course, you can test the component first by hitting F5. In this case you should modify the constructor and set the initial value to STATUS_OK or STATUS_ERROR, otherwise you will only see a blank canvas when you publish the movie. For the release version of the component set the initial value back to STATUS_UNSET. Now click on the new “Export SWC” icon and the magic happens right in front of your eyes…
If everything went ok, you will see a new file in your bin folder:

If you tested the component (like I did) you also have the SWF file in the bin folder. Actually you can delete the StatusComponent.swf file now, it’s no longer needed.
Using the StatusComponent
For a quick test of the component create a new default ActionScript 3 project in FlashDevelop, call it “StatusComponentTest”, and make the StatusComponent.swc file accessible to your project by adding its path to the new project’s classpaths. The project panel should look like this:

Now this is important: Right-click on the StatusComponent.swc file and select “Add To Library”. Otherwise the class(es) in your SWC file will not be recognized.
Here’s a simple test class (StatusComponentTest.as) that instantiates the component and sets the status to STATUS_OK. The trace() statement sends the string value of the current status to the output panel.
-
package
-
{
-
import com.log2e.components.StatusComponent;
-
import flash.display.Sprite;
-
import flash.display.StageScaleMode;
-
import flash.display.StageAlign;
-
-
public class StatusComponentTest extends Sprite
-
{
-
private var _statusComponent:StatusComponent;
-
-
public function StatusComponentTest()
-
{
-
stage.scaleMode = StageScaleMode.NO_SCALE;
-
stage.align = StageAlign.TOP_LEFT;
-
-
_statusComponent = new StatusComponent();
-
_statusComponent.status = StatusComponent.STATUS_OK;
-
addChild(_statusComponent);
-
trace(_statusComponent.status);
-
}
-
}
-
-
}
I hope you enjoyed the tutorial.
Tags: ActionScript, Flash, FlashDevelop, Flex, SWC
Whenever I try this, FlashDevelop crashes
FlashDevelop crashes for me too, error:
System.MissingMethodException: Método não encontrado: ‘System.String ProjectManager.Projects.AS3.MxmlcOptions.get_Additional()’.
em ExportSWC.PluginMain.Export(Object sender, EventArgs e)
em System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
Daniel try this:
http://curlyben.com/fd3/ExportSWCPlugins.zip
Thnx for the Tutorial. works like a charm. I am though trying to use the same exported swc in Flash CS3 with no luck. Adding the component on the stage adds nothing, while in FD works fine. Any ideas?
Hi… The tutorial is great,but with the new version of FD RC1 …there is any update chanse for this ?
Thanks
For some reason, the “ExportSWC” button remains disabled (greyed out) no matter what I do…I am running FD 3.0 RC1…has anyone solved this? I don’t want to resort back to using the command window to get this done
My icon is also grey, i’m using FD3.0 RC2, could any one tell me why?
Thanks greatly.
Andy
See this thread FD 3.0 fix:
http://www.flashdevelop.org/community/viewtopic.php?f=4&p=20260
Hi, the ExportSWC project is now an opensource project hosted by SourceForge!
http://www.sourceforge.net/projects/exportswc
You can download the latest binary, or the SVN C# source if you would like to extend/modify the project. Just send your changes to the project admins and we’ll merge it. That way there is one location for all required features.
Cheers.
Is there a way to tell that plugin to exclude classes? because i’m unsing adobe’s JSON class to parse an object and when i create the SWC it includes files in the adobe.air package which i do not use. Also by doing that i get an error because i dont have the air swc linked, because i dont neeed it.
[...] post talks about how to create a SWC using flash develop and ExportSWC this approach is great if you have say a whole library of files that have no main. [...]
Nice post,
I learned a lot of information from this post. Thanks for the effort you took to expand upon this topic so thoroughly.
I look forward to future posts.
very very useful. tnx a lot!
except main topic, learned some new things. multiplying of external movieclips and functions with get/set
Hi, I installed the plugin as described but I keep getting this message when I hit the ‘Export SWC’ icon:
*** Unable to build SWC: Project or compc.exe not found
w ExportSWC.SWCBuilder.RunCompc(String confpath)
My As3 Context config is set up properly and I can do regular projects. I have no clue how to fix that so I’d appreciate your help.
@rezid
http://www.flashdevelop.org/community/viewtopic.php?f=4&t=5731
That may help you out….
Nice tutorial.
Now, all we have to do is figure out how to get a Flex GUI designer in FD and it is on. I have a feeling that the use of Flex in a web browser component (native .Net for FD) will yield the desirable result.
SWC files are renamed zip files…
Awesome stuff.
Take care everybody!