Building an SWC library using the Flex 3 SDK

So the other day i was trying to build the AsWing library with the Flex SDK. Sadly, i failed miserably. I didn’t even know where to start. How do you feed all the files into the compiler? What command line switches to use? So after reading basically every piece of documentation that Adobe has to offer, i finally pieced it together.

And now i can proudly say, that wasn’t so hard after all, was it?
Alright, enough with the prologue. If you’re interested in the topic of build an SWC with the SDK you most likely know that you have to feed all the libraries classes into it using a manifest file. But in the case of AsWing, there are like a million files to add (give or take). So i wrote myself a handy script real quick:

var fso = new ActiveXObject( "Scripting.FileSystemObject" );
var manifest = fso.createTextFile( "src\\manifest.xml", true );

manifest.writeLine( "<?xml version=\"1.0\"?>" );
manifest.writeLine( "<componentPackage>" );

var src = fso.getFolder( "src" );
listFolder( src, manifest, "" );

manifest.writeLine( "</componentPackage>" );

manifest.close();

function listFolder( source, target, package ) {
	for( var items = new Enumerator( source.SubFolders ); !items.atEnd(); items.moveNext() ) {
		var currentFolder = items.item();
		listFolder( currentFolder, target, package + currentFolder.name + "." );
	}
	
	for( var files = new Enumerator( source.files ); !files.atEnd(); files.moveNext() ) {
		var currentFile = files.item();
		if( String( currentFile.name ).match( "\.as$" ) ) {
			var component = String( currentFile.name ).replace( "\.as", "" );
			target.writeLine( "\t<component id=\"" + component + "\" class=\"" + package + component + "\"/>" );
		}
	}	
}

So, that bad boy will build you the manifest for the given folder. I named this guy configure.js and placed it in the AsWing folder.
Now for slightly easier calling i added a small .bat to go with that. There’s only one line that matters and it is: wscript.exe configure.js

So far so good. Now we’re only missing the actual building (i’m hiliting this as JavaScript, but it’s only a .bat ;P):

@echo off

set flex_sdk_dir=path_to_flex_sdk

if (%flex_sdk_dir%) == (path_to_flex_sdk) goto sdk_missing
if (%flex_sdk_dir%) == () goto sdk_missing
if not exist %flex_sdk_dir% goto sdk_missing

if not exist src\manifest.xml goto manifest_missing

goto make

:manifest_missing
echo You have to run configure.bat first.
goto end

:sdk_missing
echo You have to set the path to the Flex SDK inside "%0.bat".
goto end

:make
echo Making...

if not exist bin md bin
set compc=%flex_sdk_dir%\bin\compc.exe
%compc% -source-path src -output bin\AsWing.swc -namespace http://aswing.org src\manifest.xml -include-namespaces http://aswing.org 


:end
echo Done.

That should be it ;) I also added these scripts to the AsWing repository.

9 Responses to “Building an SWC library using the Flex 3 SDK”

  1. vurentjie Says:

    shot-a-lot!

  2. a_[w] блог» Архив блога » Создание компонент для Flash CS3 Says:

    [...] Beginners Guide to Getting Started with AS3 (Without Learning Flex) Сборка Flex-приложений с помощью Ant Компиляция совместимых с Flash CS3 swc-библиотек с помощью Flex 3 SDK Compiling components with Flex SDK Using the Flex Compilers Building an SWC library using the Flex 3 SDK [...]

  3. zszen Says:

    it is so cool.
    but i test the file .
    it can’t build muilt-namespaces like pv3d[it include other namespace file]

  4. gencha Says:

    I just tried building it, works fine. Can’t tell you if the resulting swc works properly though.

    You can grab my build scripts and try sourself. pv3d_build.zip

  5. zszen Says:

    now i solve it .
    i saw your codes, and found that my flex sdk is old[version 3.02].
    so i download the flex_sdk_4.0.0.4021
    it is working good .

    thank you very much.

    my website is :http://zszen.com or http://zszen.cn
    welcome interchanging.

    lol.

  6. gencha Says:

    I’m not sure if you actually need the 4.0 SDK (I just use it). But as long as it works, great ;)

    Btw: I don’t understand chinese ;)

  7. zszen Says:

    now i want package all dll and exe and create one execute-file to simple create swc.

  8. gencha Says:

    I don’t think you’re allowed to re-package the stuff from the Flex SDK ;)

  9. zszen Says:

    i use swfkit make a little tools .

    zszen.com/down/buildswc.zip

Leave a Reply

You must be logged in to post a comment.