Not yet rated

Problem

Need to create SWCs from multiple MCs in a single Flash Pro Library instead of one large swc?

Solution

Create a Flash JavaScript Command.

Detailed explanation

So you have one large FLA and you need multiple MCs turned to SWCs for use in code, but you don't want one large SWC of the entire library or have to go through the pain of moving all the MCs to new FLAs?

Let's create a JSFL Command that will help you with this.

First, create a new JSFL. This is the code that will be executed:

// Get the name of the MC
function getShortName(name)
{
    var slashIndex = name.lastIndexOf("/");
    if (slashIndex > 0)
    {
        return name.substr(slashIndex);
    }
    return name;
}

// makes the name valid for directories, strips out %20 and replaces with space
function makeValidURI(name)
{
    name = name.replace(/%20/g, " ");
    return name;
}


// Export the MC to SWC
function exportMultipleSWCs()
{
    // Get the Selected Items
    var selectedItems = fl.getDocumentDOM().library.getSelectedItems();
    var i;
    // Convert selected symbols
    // If only one MC is selected, send alert that more than one need to be selected
    if (selectedItems.length <= 1)
    {
        alert("You need to select at least 2 movie clips in the Library panel.");
        return false;
    }
    else
    {
        // Choose which directory to save the SWCs in
        var dir = makeValidURI(fl.browseForFolderURL("Choose your SWC output folder:"));
        // Loop through selected MCs
        for (i = 0; i < selectedItems.length; i++)
        {
            // Get the name of the all selected MC
            var shortName = getShortName(selectedItems[i].name);
            // Append the name with .swc
            var fullSave = shortName + ".swc";
            // Save the SWC
            selectedItems[i].exportSWC(dir + "/" + fullSave);
            // Trace that saving SWC has completed
            fl.trace(shortName + " has been exported as SWC to " + dir);
        }
       
    }
}

Save this JSFL as "ExportMultipleSWCs.jsfl" in the Javascript folder in your local Flash user configuration:
[USER] / [AppSupport] /Adobe/Flash CS5/en_US/Configuration/Javascript.

 

Next, create a new JSFL. This is the one that is run from the Commands menu:

fl.runScript(fl.configURI + 'Javascript/ExportMultipleSWCs.jsfl', 'exportMultipleSWCs'); 
// runscript(config dir + JSFL to run, the method in JSFL file to run);

Save this JSFL as "Export MCs as SWC.jsfl" to the Commands folder in your local Flash user configuration:
[USER] / [AppSupport] /Adobe/Flash CS5/en_US/Configuration/Commands

Close both JSFLs.


Usage

In any Flash Pro Library, highlight multiple MCs. Go to Commands > Export MCs as SWC. Choose your exporting directory and click Choose.

You now have multiple SWCs created from all selected MCs.


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes