Setting Up the HTML File

The standard practice is to test a Flash project or SWF within an HTML file. The big plus with this approach is that if we need to test using FlashVars, we can do so with relative ease from within the HTML. So next we will create an HTML file from scratch. We’ll do this via the echo task in Ant, because it allows us to easily write to a file. But how do we automatically get the project properties in our HTML? Well, we are going to do something new here: work with tokens, and replace them with real values.

The advantage with token replacement is that we can work with template files—whether they are physically on the filesystem, or saved in properties/strings and generated with code. For now, we are choosing the latter.

The HTML we are creating has the following tokens:

  • @html.title@

  • @html.bgcolor@

  • @html.width@

  • @html.height@

These are placeholders for the code to be, which is the value we will replace using Ant so this can become a working HTML file. Of course, you can replace anything you want.

So, first, we need to create a target that will write the HTML. And since we want to distribute only the build files and property files, we want to try to generate as much as possible with Ant.

The way of embedding the SWF file in the HTML normally requires a JavaScript file called SWFObject. As of version 2, you can include this file straight from its repository, which means no more distributing extra unnecessary files. Just make a call to http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js ...

Get Automating ActionScript Projects with Eclipse and Ant now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.