JavaSWF2
Installation and Requirements
There are no special installation instructions - JavaSWF2 is provided as Java source code and it is assumed that you know how to compile it.
JavaSWF2 requires JDK 1.2 (Java 2) or later. It is pure Java and has no native platform dependencies.
Features
JavaSWF2 provides parsing and generating facilities for Flash 4 and Flash 5 content.
Transparent JPEGs and Sound are not implemented in this release, but they are on the list. Also - ActionScript is only supported in its compiled form (action codes) - support for ActionScript source is also on the list.
JavaSWF2 Architecture
The code centers around the interfaces defined in the com.anotherbigidea.flash.interfaces package. These interfaces are used to pass various information about the contents of a Flash SWF file. The SWF parsers and writers implement these interfaces and drive other classes that implement them.
There are two levels within JavaSWF2 - the file format level and a more abstract object model. The file format level provides access to all the details of the SWF file format - both in parsing and in writing - and is useful if you have knowledge of the file format and need to implement fast and optimal parsing or generating code.
The object model level is implemented by the classes in the com.anotherbigidea.flash.movie package and provides a means to access and create SWF content without knowing all the details of the file format.
Refer to the Summary of Classes below for further details.
XML to/from SWF
The DTD for the XML representation of SWF is given in javaswf-dtd.txt
To compile the classes mentioned below you will need the org.xml.sax.. packages in the classpath. These are the standard SAX(2) interfaces that are included in the JavaSWF2 releases and should also come included in all recent XML parser packages. The Apache Xerces and Crimson parsers are recommended - but any compliant SAX2 parser will do.
To convert from SWF to XML use the com.anotherbigidea.flash.readers.SWFSaxParser class. This implements the standard org.xml.sax.XMLReader interface - so it looks like an XML parser. It also implements SWFTagTypes and so can be driven by a SWF parser. The main method of SWFSaxParser is a command line utility to read a SWF and write out XML.
To convert from XML back to SWF use the com.anotherbigidea.flash.writers.SWFSaxWriter class. This can be driven by any SAX2 XML parser and will drive a SWFTagTypes implementation. There is no utility provided for XML to SWF since this would mean a dependency on a particular XML parser (until JAXP in incorporated). However, there is a sample provided below of how to hook up the Xerces parser to produce SWF output.
Samples
More documentation will follow. However, the following samples provide an introduction to using JavaSWF2:
How to unprotect a SWF file: See the com/anotherbigidea/flash/Unprotector.java class in the distribution file.
How to parse a SWF and dump its contents as text.
How to extract all the static text in a movie.
How to create a simple movie at the file format level.
How to create a simple movie using the object model.
How to append some frames to an existing movie.
How to create a Movie object from an existing SWF.
How to create text using the object model.
How to load a JPEG using the object model.
Sample of writing frame actions.
How to convert an XML file to SWF.
VerdanaFont.swf - font used by the TextHigh.java sample.
Summary of Classes
Package
com.anotherbigidea.flash
Unprotector
Simple Utility to unprotect
a Flash movie
SWFConstants
Constants used by many of
ther other packages - including tag type codes and various flags
SWFActionCodes
Constants used in Action
Script processing
Package
com.anotherbigidea.flash.interfaces
SWFHeader
Interface for passing the
SWF File Header details
SWFTags
Interface for passing
the contents (as a blob) of a SWF tag (extends SWFHeader)
SWFSpriteTagTypes
Interface for passing the
details of the tags that can be used in both the main
timeline and sprite timelines (extends SWFTags)
SWFTagTypes
Interface for passing the
details of the remainder of the tags that can only be used in the main
timeline (extends SWFSpriteTagTypes)
SWFActions
Interface for passing
action codes
SWFVectors
Interface for passing Shape
and Glyph vectors
SWFShape
Interface for passing Shape
style definitions and style changes (extends SWFVectors)
SWFText
Interface for passing text
records as part of the definition of the SWF Text definition tags
Package
com.anotherbigidea.flash.readers
SWFReader
Reads a SWF file input
stream and passes the header and tag contents to any implementation of the
SWFTags interface.
TagParser
Implements the SWFTags
interface. Parses the contents of all tags and passes the
detail to any implementation of the SWFTagTypes interface.
ActionParser
Parses an action code array
(chunk of compiled ActionScript) and drives any implementation of the
SWFActions interface.
SWFSaxReader
Implements SWFTagTypes and the XML standard
SAX2 XMLReader interface. Converts SWF to XML.
MovieBuilder
Implements the SWFTagTypes
interface and builds an instance of the
com.anotherbigidea.flash.movie.Movie "object model" class.
Package
com.anotherbigidea.flash.writers
SWFWriter
An implementation of the
SWFTags interface that writes to an output stream or file. SWFWriter
will also calculate the length and frame count of the movie if not
known.
TagWriter
An implementation of the
SWFTagTypes interface that reconstructs the tags in binary form and writes
them to any implementation of the SWFTags interface.
ActionWriter
An implementation of the
SWFActions interface that builds a binary action code array.
ActionTextWriter
An implementation of the
SWFActions interface that writes a textual representation of the action
codes.
SWFSaxWriter
An implementation of the
standard SAX2 ContentHandler interface that drives any implementation of SWFTagTypes. When
driven by a SAX2 XML Parser will convert XML back
to SWF.
SWFTagDumper
An implementation of the
SWFTagTypes interface that writes a textual representation of the entire
Flash movie.
SWFTagTypesImpl
An implementation of the
SWFTagTypes interface that passes all the method calls directly to another
implementation of the same interface. Useful as a parent class
when implementing tag filters.
SWFActionsImpl
An implementation of the
SWFActions interface that passes all the method calls directly to another
implementation of the same interface. Useful as a parent class when
implementing action filters.
DummySWFWriter
An implementation of the
SWFTags interface that does nothing - use as a sink when output is not
required.
Package
com.anotherbigidea.flash.structs
...
Various structures used
in the other packages
Package
com.anotherbigidea.flash.movie
Movie
The root class in the Flash
object model.
...
Other classes represent
different symbol types in the object model.