Changing MovieClip Class Name via JSFL

Re-factoring your classes’ package path isn’t so bad. With 1 find and replace command in Dreamweaver/FlexBuilder, you can change it from “company.” to “com.company.” in just 3 seconds on all of your classes without having to open all, or any of them.

…this isn’t so easy with MovieClips in Flash. FLA is binary, and to access the AS2 class name, which associates a MovieClip with your class, you have to right click on a symbol in the library, manually change the name in a cramped text input field, and click ok… then repeat this for your other 39 classes, or more.

Or you could use JSFL. Programmer I work with educated me why you prefix class paths with “com.” and “net.”. I’ve forgotten why it’s important, could of sworn at the time I had an epiphany of understanding, but regardless, here’s the code to quickly change all of your AS2 + linkage ID’s to point to a new class path/linkage ID name. I include linkage ID because typically your linkage ID and AS2 class path are, and should be, identical.

function d(o)
{
        fl.trace(o);
}

function init()
{
        fl.outputPanel.clear();
        var i = fl.getDocumentDOM().library.items.length;
        while(i--)
        {
                var linkage = fl.getDocumentDOM().library.items[i].linkageIdentifier;
                var className = fl.getDocumentDOM().library.items[i].linkageClassName;
                var testingString = className;
                if(testingString != null)
                {
                        if(testingString != "")
                        {
                                var a = testingString.split(".");
                                if(a[0] == "roundboxmedia")
                                {
                                        a.unshift("com");
                                        d("old:");
                                        d(fl.getDocumentDOM().library.items[i].linkageIdentifier);
                                        d(fl.getDocumentDOM().library.items[i].linkageClassName);
                                        fl.getDocumentDOM().library.items[i].linkageClassName = a.join(".");
                                        fl.getDocumentDOM().library.items[i].linkageIdentifier = fl.getDocumentDOM().library.items[i].linkageClassName;
                                        d("new:");
                                        d(fl.getDocumentDOM().library.items[i].linkageIdentifier);
                                        d(fl.getDocumentDOM().library.items[i].linkageClassName);
                                }
                        }
                }
        }
}

init();

One Reply to “Changing MovieClip Class Name via JSFL”

Comments are closed.