Monthly Archives: December 2010

Create Flash Documents Programmatically

Sometimes it’s very useful to be able to create flash documents programmatically (e.g. batch conversions). Adobe Flash supports automation via the JavaScript Flash language (JSFL). Finally when the script is finished you can call it from the command line using AppleScript.

How it works exactly is demonstrated in the following one minute screencast:

Embedding Flash Into Java Applications

To be able to embed Flash into a Java application one needs a third party library. ComfyJ from TeamDev is such a library.

ComfyJ is a bidirectional Java-COM bridge which allows me to use ActiveX/COM objects from Java.

Here a screenshot with a SWF running inside a Java Swing user interface:

In Java the initialization looks like:

    private static final String FLASH_PROGID = "ShockwaveFlash.ShockwaveFlash";
    private OleContainer _container = new OleContainer();



        getContentPane().add(_container, BorderLayout.CENTER);
        addWindowListener(new WindowAdapter()
            public void windowOpened(WindowEvent e)

            public void windowClosing(WindowEvent e)

Some simple helper methods:

    private void createOleObject()

    private void showOleObject()

    private void destroyOleObject()

To open a SWF file:

            OleMessageLoop.invokeMethod(this, "openFile", new Object[]{filename});

And finally here is the openFile method:

    public void openFile(String filePath)
        File file = new File(filePath);

        if(!file.exists()) {
            throw new RuntimeException("Couldn't find file with movie: " + filePath);

        IDispatchImpl flash = new IDispatchImpl(_container.getOleObject());
        Automation flashAutomation = new Automation(flash);

        // load movie
        flashAutomation.setProperty("Movie", filePath);

The class path should look similar to:


And don’t forget to pass a parameter to the Java VM with the (relative) path to the folder with the native DLLs:


BTW, I’m not associated with TeamDev other than being a mostly happy user. Here’s the link to the library: