Publishing to Flash 8 with Swfmill and MTASC (or The Return of The Peeing Dog)

There's already quite a bit of information on creating Flash 8 SWFs using MTASC on the FlashCoders Wiki project on OSFlash. In this post, I am going to show you how Swfmill can also output Flash 8 SWFs and how you can use MTASC and Swfmill together to create Flash 8 SWFs using the Natural Entry Point Method.

And yes, the peeing dog is making another appearance.

Creating a Flash 8 SWF using the Natural Entry Point Method is essentially the same as creating a Flash 7 or 6 SWF. To demonstrate, let's make a peeing dog toggle a drop shadow when clicked (this is probably the first time in the history of mankind that this is being attempted, so download the source code and follow along very carefully!)

To start, create a folder for your project. Call it something descriptive, like PeeingDogWithDropShadow.

Inside it, create a folder called "src" for your (drumroll) source files and one called "build" in to which your compiled SWFs will be placed. Finally, inside the src folder, create a folder called "library". This will house a SWF, created using the Flash IDE, containing the animation of the peeing dog (PeeingDog.swf, which is part of the source code download for this example.)

Next, using your favorite editor (OK, your second-favorite will also do), create the main SWFML file for your application (application.xml) and place it in the src folder. The code for it is below:

SWFML:
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2.  
  3. <movie version="8" width="240" height="170" framerate="30">
  4. <background color="#ffffff"/>
  5. <clip import="build/classes.swf" />
  6. <frame>
  7. <library>
  8. <clip id="Application" class="Application" />
  9. <clip id="PeeingDog" class="PeeingDog" import="src/library/PeeingDog.swf" />
  10. </library>
  11. <place id="Application" name="app" x="0" y="0" depth="1000" />
  12.  
  13. </frame>
  14.  
  15. </movie>

Notice the version="8" attribute in the movie tag. That's where the magic is :) That will make Swfmill spit out (yuck) a Flash 8 SWF.

Also notice that you are asking Swfmill to import a SWF called classes.swf from the build folder. Needless to say that file doesn't exist yet. Once you have created the two classes you will be using for this example, you will ask MTASC to compile them into the classes.swf file for inclusion in the final application by Swfmill.

So, without futher ado, create the main Application class that will linked to the Application movie clip:

ActionScript:
  1. class Application extends MovieClip
  2. {
  3. {
  4. // Attach an instance of the peeing dog
  5. attachMovie ("PeeingDog", "peeingDog", 1000);
  6. }
  7. }

As you can see, it's very simple. All it does is attach an instance of the PeeingDog clip on to the stage.

Here's the code for the PeeingDog class:

ActionScript:
  1. // Import the Flash 8 DropShadowFilter class from the
  2. // standard library in MTASC.
  3. import flash.filters.DropShadowFilter;
  4.  
  5. class PeeingDog extends MovieClip
  6. {
  7. var ds:DropShadowFilter;
  8. var showDs:Boolean = false;
  9.  
  10. function PeeingDog()
  11. {
  12. // Create an instance of the drop shadow filter
  13. ds = new flash.filters.DropShadowFilter();
  14. }
  15.  
  16. function onRelease ()
  17. {
  18. // Toggle the drop shadow
  19. showDs = !showDs;
  20. filters = showDs ? [ ds ] : null;
  21. }
  22. }

In the PeeingDog constructor, you create an instance of the drop shadow filter and then, when the dog is clicked, toggle it on and off by setting the movie clip's filters property. Notice how the filters property is an array. This allows you to add more than one filter to a movie clip in Flash 8 but it also means that even if you are adding a single filter, you still have to wrap it up an array.

Finally, you need to compile the AS2 and SWFML files and build this project.

To start, you need to tell MTASC to compile the two classes you just wrote and place them in a SWF.

To do this, make sure that MTASC and Swfmill are both on your system's path and then open up a command line window and, from the root folder of your project (the one that contains the src and build folders), type the following command:

mtasc -version 8 -swf build\classes.swf -header 1:1:30 -cp src Application.as PeeingDog.as

This will create a Flash 8 SWF (-version 8) called classes.swf in the build folder (-swf) that has dimensions of 1px x 1px and a frame rate of 30fps (-header). It will include the src folder in the classpath (-cp) and compile the Application and PeeingDog classes into the SWF.

Next, tell Swfmill to compile the SWFML file for the main application using the following command:

swfmill simple src/application.xml build/application.swf

To make it simpler for you, I've provided a file called build.bat that you can run which contains both these instructions.

Once you have built the project, you should find two SWFs in your build folder: classes.swf and application.swf.

Double-click the application.swf file to launch it in the Flash 8 Beta Player. Click on the doggie to toggle his drop shadow on and off.

As I was saying last night at the London MMUG after presenting the Flash JavaScript Integration Kit using an example of a clown that honks its horn when you scroll the web page: Isn't it amazing what you can produce given thousands of dollars worth of hardware and software and years of diligent study? :P

Download the code (38KB).

Creative Commons License This code is licensed under a Creative Commons Attribution-ShareAlike 2.0 England & Wales License.

Comments