FAMES: FAME + Swfmill = Fully open source flash

The acronyms they keep a-growin'. I started out with AME (ASDT, MTASC and Eclipse), got the Flashout plugin working and entered the world of FAME before getting my Borg on and assimilating _root. I knew I was well on my way to open-source Flash development but there was still a piece of the puzzle missing: How do I create my initial SWF, its library, resources, etc.

Enter swfmill by Daniel Fischer. Swfmill is a wonderful little command line tool that allows you to go from XML to SWF (using a dialect called swfml) and vice-versa. The path to totally open-source Flash development thus makes our acronym FAMES (which I'm sure Jesse would pronounce "famous"!)

Here are the steps to recreate the FAMES swf you see above:

1. Create a new ActionScript project in ASDT (Eclipse)

2. Create a new XML file called application.xml. This is the swfml file that Swfmill will compile to create the skeleton swf that contains your library.

3. Add the following code to the swfml file:
XML:
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <movie width="320" height="240" framerate="30">
  3. <background color="#ffffff"/>
  4.  
  5. <frame>
  6. <library>
  7. <clip id="spheres" import="library/spheres.png"/>
  8. </library>
  9. </frame>
  10. </movie>
4. Create a new AS File to use as the main application class and call it Application.as. Here is the code for Application.as:
ActionScript:
  1. class Application extends MovieClip
  2. {
  3. var tfCaption:TextField;
  4. // Clips attached dynamically from Swfmill library
  5. var mcSpheres:MovieClip;
  6.  
  7. var sW:Number = null; // Stage width
  8. var sH:Number = null; // Stage height
  9. private function Application ( target )
  10. {
  11. // Link movie clips to classes
  12. Object.registerClass ( "spheres", Particle );
  13. // Assimilate the target
  14. target.__proto__ = this.__proto__;
  15. target.__constructor__ = Application;
  16. this = target;
  17.  
  18. Flashout.log ("Application initialized: " + this );
  19. // Store stage dimensions for easy look-up
  20. sW = Stage.width;
  21. sH = Stage.height;
  22. // Draw border around the stage
  23. lineStyle ( 1, 0x000000 );
  24. moveTo ( 0, 0 );
  25. lineTo ( sW, 0 );
  26. lineTo ( sW, sH );
  27. lineTo ( 0, sH );
  28. lineTo ( 0, 0 );
  29. //
  30. // Create a caption
  31. //
  32. var captionTextFormat = new TextFormat();
  33. captionTextFormat.size = 12;
  34. captionTextFormat.font = "_sans";
  35. var captionText:String = "Made with FAMES (FAME + Swfmill)";
  36. var captionTextExtent:Object = captionTextFormat.getTextExtent ( captionText );
  37. var captionWidth:Number = captionTextExtent.textFieldWidth;
  38. var captionHeight:Number = captionTextExtent.textFieldHeight;
  39. var captionX = sW / 2 - captionWidth / 2;
  40. var captionY = sH - captionHeight;
  41. createTextField( "tfCaption", 10000, captionX, captionY, captionWidth, captionHeight );
  42. // Write caption text
  43. tfCaption.text = captionText;
  44. // Add ten particles
  45. for ( var i = 0; i < 10; i++ )
  46. {
  47. // Attach a sphere clip
  48. attachMovie ("spheres", "mcSphere", 1000 + i );
  49. }
  50. }
  51. static function main ()
  52. {
  53. // Create an Application instance and
  54. // have is assimilate _root.
  55. var test:Application = new Application( _root );
  56. }
  57. }

The important new bit of functionality here concerns linking the "spheres" clip to the Particle class (achieved with the Object.registerClass statement in the constructor) and attaching instances of it on stage.

5. Here is the code for the Particle class:
ActionScript:
  1. class Particle extends MovieClip
  2. {
  3. var vX:Number = null;
  4. var vY:Number = null;
  5. var randomness:Number = null;
  6.  
  7. function Particle ()
  8. {
  9. Flashout.log ( "Particle created: " + this );
  10. _x = _width + Math.random() * ( Stage.width - _width );
  11. _y = _height + Math.random() * ( Stage.height - _height );
  12. _rotation = Math.random() * 360;
  13. var randomness = Math.random()*5;
  14. vX = Math.random() * randomness + 1;
  15. vY = Math.random() * randomness + 1;
  16. }
  17. function onEnterFrame ()
  18. {
  19. _rotation += 1.69;
  20. _x += vX;
  21. _y += vY;
  22. if ( _x < 0 || _x > ( Stage.width - _width/2 ) )
  23. {
  24. vX *= -1;
  25. _x += 2 * vX;
  26. }
  27. if ( _y < 0 || _y > ( Stage.height - _height/2 ) )
  28. {
  29. vY *= -1;
  30. _y += 2 * vY;
  31. }
  32. }
  33. }

Before compiling the project, you need to use Swfmill to create the application.swf. To do this, open up a command prompt and enter the following command from your project folder (make sure you add swfmill.exe to your path first):

swfmill simple application.xml application.swf

6. Finally, you need to configure Flashout. To do this, browse to the Application class to set it as the "Root (main) class" and browse to the application.swf file created by Swfmill to set it for the "Path to swf" option. Hit "compile" and you should see the SWF run!

FAMES opens up a whole new world of cool possibilities.

Download the Swfmill particles example (12k)

Comments