Export SWC without the SWF

Posted 26 July 2010 by

Update – 24 Augusts 2010:

I’ve packaged this into a MXP file so now you can just install it! In the source bundle you’ll find the JSFL, MXI and the MXP. Execute the MXP file to install the script. The other two files are just the source files used for packaging the MXP.

  • ExportSWC – Includes all source and MXP file.

Original Post:

I wrote this jsfl script in response to this feature request from the Flash community.

Copy the source below and save it as “Export SWC.jsfl” in your Commands directory. The Commands directory can be found at C:\Users\{USER_NAME}\AppData\Local\Adobe\Flash CS5\en_US\Configuration\Commands on windows and /Users/{USER_NAME}/Library/Application/Support/Adobe/Flash/CS5/en_US/Configuration/Commands on Mac.

var dom = fl.getDocumentDOM();
var domFolder = getDomFolder();
var publishURI = getPublishURI();

dom.publish();

if(FLfile.exists(publishURI))
	FLfile.remove(publishURI);

function getPublishURI()
{
	var profileXML = new XML(dom.exportPublishProfileString()).children();

	for(var i = 0; i < profileXML.length(); i++)
	{
		var node = profileXML;
		switch(String(node.name())){
			case "PublishFormatProperties" :
				return domFolder + "/" + String(node.flashFileName);
			break;
		}
	}
}

function getDomFolder()
{
	var splitURI = dom.pathURI.split("/");
	splitURI.pop();
	return splitURI.join("/");
}

You might need to restart Flash to make it appear in your “Commands” menu.

CS5 changed changed the shortcut for publishing from “shift+F12″ to “shift+alt+F12″, so let’s set a shortcut for this script file to “shift+F12″.

Go to Edit -> Keyboard Shortcuts… and assign the “Export SWC” shortcut to “shift+F12″.

Export-SWC-Shortcut

Export-SWC-Shortcut

Please note this script does not automatically flag “Export SWC” to true, so you still need setup your publish profile as per usual.

Export-Settings

Export-Settings

Now you can simply press “shift+F12″ to export your SWC only!

Post Details

  • http://www.beautifycode.com/two-inertia-movements Marvin

    that´s really freaked out – but good one. thanks :)

  • Pingback: Tweets that mention Export SWC without the SWF | Matan Uberstein | AS3 Blog -- Topsy.com

  • Pingback: Using Assets in FDT (Flash > SWC > Linked Library) | Beautify Code Blog

  • http://polprav.blogspot.com/ egorodet

    it was very interesting to read http://www.matanuberstein.co.za
    I want to quote your post in my blog. It can?
    And you et an account on Twitter?

    • http://doesflash.com Matan Uberstein

      Go ahead :)

  • Pingback: Tweets that mention Export SWC without the SWF | Matan Uberstein | AS3 Blog -- Topsy.com

  • http://profiles.google.com/pavel.fljot Pavel fljot

    // Extra copy, in case I lose all my data)

    //—————————–
    // GLOBALS
    //—————————–

    // output buffer
    var output = “”;

    // shortcut to trace
    trace = fl.outputPanel.trace;

    // temp path for code (should be added to classpath in fla actionscript settings)
    var tempClassPath = FLfile.platformPathToURI(document.path.substr( 0, document.path.lastIndexOf(“/”) + 1) + “code/”);

    //—————————–
    // FUNCTIONS
    //—————————–

    // trace to output buffer
    function dtrace(s)
    {
    output += “n” + s;
    }

    function getClassFileContents(item, package, className)
    {
    dtrace(“package ” + package + ” {n”);
    // print class header
    dtrace(“nt/**”);
    dtrace(“t * This is dummy class, not for actual use.”);
    dtrace(“t */”);
    dtrace(“t import flash.display.MovieClip;”);
    dtrace(“t”);
    dtrace(“tpublic class ” + className + ” extends MovieClip {“);
    //close class
    dtrace(“t}”);
    //close package
    dtrace(“}”);

    var retVal = output;
    output = “”;

    return retVal;
    }

    // Handy script by Matan Uberstein:
    // publishes swf + swc, remove swf
    // @see http://doesflash.com/2010/07/export-swc-without-the-swf/

    var dom = fl.getDocumentDOM();
    var domFolder = getDomFolder();
    var publishURI = getPublishURI();

    function getPublishURI()
    {
    var profileXML = new XML(dom.exportPublishProfileString()).children();

    for(var i = 0; i < profileXML.length(); i++)
    {
    var node = profileXML[i];
    switch(String(node.name())){
    case "PublishFormatProperties" :
    return domFolder + "/" + String(node.flashFileName);
    break;
    }
    }
    }

    function getDomFolder()
    {
    var splitURI = dom.pathURI.split("/");
    splitURI.pop();
    return splitURI.join("/");
    }

    function main()
    {
    fl.outputPanel.clear();

    var path = tempClassPath;
    trace("ClassPath: " + path);

    var items = fl.getDocumentDOM().library.items;
    var n = items.length;
    var item;
    var folders;
    var baseClassName;
    var baseClassFile;

    for (var i = 0; i < n; i++)
    {
    item = items[i];

    if (item.linkageClassName == null) continue;
    if (item.linkageBaseClass == "" || item.linkageBaseClass == "flash.display.MovieClip") continue;

    folders = item.linkageBaseClass.split(".");
    baseClassName = folders.pop();

    // check for folder
    var folderPath = "";
    for (var j = 0; j < folders.length; j++)
    {
    folderPath += folders[j] + "/";
    if (!FLfile.exists(path + folderPath))
    {
    FLfile.createFolder(folderPath);
    trace( ' – created folder ' + folderPath );
    }
    }
    // check for file
    baseClassFile = path + folderPath + baseClassName + ".as";
    trace("Checking file: " + baseClassFile);
    if (!FLfile.exists(baseClassFile))
    {
    // write file
    FLfile.write(baseClassFile, getClassFileContents(item, folders.join("."), baseClassName));
    }
    }

    trace('n Fake classes created successfully.nn—');

    trace('n Compiling swc…nn—');

    dom.publish();

    if (FLfile.exists(publishURI))
    {
    FLfile.remove(publishURI);
    }
    if (FLfile.exists(tempClassPath))
    {
    FLfile.remove(tempClassPath);
    }

    trace('n SWC compiled successfully.nn—');
    }

    // run…
    main();

  • http://twitter.com/RumblingSkies erik van nieuwburg

    Nice nice nice! Thanks for the tip!

    • http://doesflash.com Matan Uberstein

      My pleasure :) Enjoy!

  • Anonymous

    Just installed this into CS4 mac and it doesn’t work. swf still shows up in target directory.

    • http://doesflash.com Matan Uberstein

      Hey, was it a xfl file maybe? I found that this script doesn’t work for xfl files, only fla files, sorry. I’m sure it can be modified easily to work for xfl as well.

      • Anonymous

        Nope, just a new .FLA. I do have “Include hidden Layers” and “Include XMP metatdata” unchecked. Not sure if that makes a difference.

        • http://doesflash.com Matan Uberstein

          Try doing a fl.trace(publishURI); in the script file directly after dom.publish(); Maybe that could shed some light, because I just tried a test file that matches your export settings and it works for me. I am on Win7 CS5 though.

          If you find a solution, please enlighten us :) – Thanks!