Current location: Brighton, UK

SwfCreator 3000 v0.2 - now with swfmill support!

Posted on Wednesday, May 14, 2008 @ 13:49 CET

SwfCreator 3000

After playing with version 0.1 of the script for a little while we came up with few ways to make it even sexier so I spent a few hours last nite hacking together some new cool features, first and foremost swfmill support! Download the archive here, and read on for instructions.

What does it do?

The script loops overs a list of SWFs you have defined in an XML file and uses swfmill to create an asset SWF. Once that is done MTASC injects in your code along with any variables you have defined and spits out a SWF containing both. All you need to do is specify the path to the SWF and your classes and the name of your main class that starts up the app.

Variable injection explained

Before each SWF is compiled, SwfCreator modifies your main class a little by adding the variables you've defined to the _global scope. If this sounds dirty to you, I agree and you're right, BUT, to avoid polluting _global we create a single Object - you decide its name - and add all the variables as its properties.

So basically, if the global object name is Cheese, and you have a variable called clickUrl, then you can access it in your code at runtime by calling _global.Cheese.clickUrl.

Having them on _global also makes it easier to test things before you do this for multiple SWFs and then simply commenting out the block.

How do I use it? - slightly different

First you define your project properties in a file called project.xml (you can always call it something else). This file includes the following:

  1. a list SWFs that are going to be compiled and their desired filename
  2. for each SWF we have two sub nodes now, movie and code
  3. movie is SWFML (an XML schema that swfmill understands, more info here) that defines the properties of the file to be created such as the filename, width, height, framerate and Flash version (upto and including 8). It also defines the contents of the library, so here you define all the assets to be included which can be images, fonts or SWFs (with embedded assets within them)
  4. code defines the path to where your classes are located (aka classpath) and the name of the main class that contains the MTASC entry path that starts up your SWF. If this is new to you, don't worry its simple - check this example over on the MTASC site. The variables that are to be included also go here

Finally you have to define the name of the object to be created on the _global scope for variable injection, and whether or not to use MTASC in strict mode (on by default).

The sample project.xml file looks like this:

Project file

A quick example

Now that you know how it all is put together, you can download the ZIP archive from here. Then:

  1. extract it somewhere (say the desktop)
  2. launch Terminal.app (/Applications/Utilities/Terminal.app)
  3. in the Terminal, change directory to where you extracted it. So for the desktop: cd Desktop now we run the script with the sample project.xml file like so:
./SwfCreator3000.pl -x example/project.xml

This will build the two sample SWFs and put them in the example/bin folder. The included sample project will show you how to embed and use movieclips (exported from within another SWF), a TrueType font (Narkism found over on FlashKit as freeware), and a PNG image. I think that should cover most bases.

Notes!

This is still an alpha version so things might break, if so just let me know. Also this has only been tested on OS X 10.5 (Leopard) with the version of Perl that ships with it (5.8.8, to check run perl -v from the Terminal). Also:

  • the width/height/framerate settings now work! :)
  • strict mode is now set correctly
  • and finally, due to my still lacking 1337 regular expression skillz, the main() MTASC entry point must have the opening brace on the same line and NOT be typed. So static function main() { is fine, static function main():Void (and the opening brace on the next line) is not

Ok, that's it! Give me a shout if it helps you out :)

Update (16-05-2008): Version 0.2.1 fixes an issue where multiple clips and/or fonts were being output incorrectly to swfmill.

- paulo

Post a comment:

You must have Flash and JavaScript enabled to post a comment.