Using SwishMax generated SWF assets with OpenFL

With the discontinuation of Adobe’s Flash plugin for the browser at the end of 2020 and the rise of the HTML5 standard, a lot of former Flash developers moved to OpenFL because of it’s similar API and the possibility to deploy to a number of other targets.
For some years OpenFL is capable of using assets – MovieClips, Sprites, Graphics, Shapes – from swf files but how do we generate such an asset swf?
The most straight-forward and obvious solution is using Adobe’s Flash creation suites e.g. Flash CS2 but personally I always disliked it’s user interface. It’s bloated, confusing and creating even the most simple animation is a pain in the … There’s hope though!
Some of you might remember there was a competitor the times flash was hot: SwishMax! The user interface was waaay cleaner and it even had hundreds of built-in effects you could simply apply to objects.
Unfortunately SwishZone, the creator of this tool has gone out of business. Luckily though they provided a key generator to unlock the software. Their website has gone too but archive.org still serves the generator and the program itself, so grab those here:
The last release was SwishMax 4 but if you like you can also get SwishMax 2. The unlock key generator is here.

Sadly OpenFL can’t use SwishMax generated SWFs directly because it expects those to be an AVM2Movie to be able to access individual assets inside the SWF. Even though SwishMax offers an option to set the swf version up to 10, it still exports an AVM1Movie only.
The solution might seem obvious: we need to convert that AVM1 to an AVM2 movie! You’ll be shocked but there’s no thing such as a converter! With AVM2 came ActionScript 3.0 which is a completely different thing. Actually if you’re using the flashplayer browser plugin, internally it’s using two different virtual machines to playback AVM1 and AVM2 movies.

With a little bit Visual Basic Script and a number of tools we’re still able to generate an AVM2Movie out of a SwishMax generated SWF.

Prerequisites:

  • Windows 7 or above
  • FlashDevelop 4.6+
  • Adobe Flex SDK
  • Java Runtime Environment 7+
  • OpenFL version 7.1.2 or above
  • Lime version 6.2.0 or above
  • Haxe 3.2.1 or above
  • SwishMax 2+

I won’t walk you through using SwishMax – I assume you know how to use it! To be able to use an asset from a SwishMax SWF, the object’s Target checkbox must be ticked and it needs to have a name.
This is done by selecting the object inside the Outline panel (A) and doing the aforementioned changes in the Properties panel (B).

swishmaxOutline

We’re not done yet – afterwards you need to right-click the object in the Outline panel and select Object attributes. In the dialog head to Assets, tick Enable asset and finally give the asset a name.

swishmaxAttributes

To make your life a little easier you might use this pre-made SwishMax .swi project file to work with.

To compile the project to a .swf file, press ctrl + e and select a folder on your harddrive.
Now we need to create some windows batch and Visual Basic Script files – so open a TextEditor of your choise e.g. NotePad and paste this snippet:

FLEX_SDK should reflect the path to Adobe’s Flex SDK on your harddrive and oviously JAVA_HOME and PATH, the path to the Java Runtime Environment. Save the file in the same folder as assets.swf and give it the name generateMain.bat.

This batch file will invoke the Flex SDK’s swfdump tool, which will generate a .xml file containing all the tags used inside the swf. What we’re after are the ExportAssets nodes inside the .xml which contain the name of the assets, face and rotatingText respectively. We need those names to generate an ActionScript file which will ultimately embedd those assets in the final AVM2Movie. This is done by the call to generate.vbs which we’ll work on next.

Create a new empty file and paste the following lines:

and save it as generate.vbs in the same folder.
Now open a command prompt, go to that folder and execute generateMain.bat. If everything went well you should have a file called Main.as which looks like this:

As a side note – the above could be done by hand but if there are numerous assets some sort of automation comes in handy.

In the next step we’ll utilize FlashDevelop’s command line compiler fdbuild (which relies on the Flex SDK’s compiler) to finally compile an AVM2Movie! But wait – fdbuild needs a project file to be able to compile something!
Once more create a new empty file in your editor and paste these lines:

and save it as AssetConverter.as3proj – again in the same folder as all the other files.

Now we need one last batch file to fire up the command line compiler. So for the last time start a new empty file, paste the following:

and save it as assetsAVM2.bat.
FLASH_HOME must point to the FlashDevelop installation on your harddrive!
At the command prompt execute this file and finally you should have a file called assetsConverted.swf in your folder!

That wasn’t too hard, was it? Okay – I must admit it is quite cumbersome but luckily you can reuse all of the above snippets for any project!

Now that we finally have the required AVM2Movie, let’s use it!
Start FlashDevelop and create a new OpenFL project from the template wizard. Give it the name SWFAssets.
swishmaxFDCreateCopy the just compiled assetsCONVERTED.swf file into the assets folder of your project e.g. C:\Users\EnigmaticCoder\Documents\SWFAssets\assets
To make OpenFL aware of the assets file, we need to declare it inside the projects project.xml file.
Simply add this line:

We’re almost done! Everything that’s left is instantiating one of those swf assets and add it – flash-like – to the display list!
In OpenFL accessing an external swf asset is done by utilizing the Assets class getMovieClip() function.
Open Main.hx inside FlashDevelop and add the following lines inside the constructor function new()

As you can see the parameter given to getMovieClip is assetsCONVERTED – which simply is the name of the swf without the file extension – followed by a semicolon and finally the name of the asset you want to use. If you look back it is actually just called rotatingText. We need to prepend Main_ because we embedded the asset in the Main class when we utilized FlashDevelop’s fdbuild tool to generate the AVM2Movie.
Well – that’s it! If we also add the second asset, arrange both nicely and deploy to html5, you’ll have something like this:

Leave a Reply

Your email address will not be published. Required fields are marked *