We will develop a minimalist example of a factory method pattern in ActionScript 3.0 using Flash CS3. The Project window shown in Figure 2-3 mirrors the file structure for the example.
Figure 2-3. Project window for the minimalist example
The Factory Method Minimalist.fla is a Flash
document whose document class is defined as Main
.
The document class is a new feature in Flash CS3 that can be
set from the Properties tab in the Properties panel of a Flash document (.fla file). This represents the class whose
constructor will be automatically run by the Flash Player when the Flash movie
(.swf file) is loaded. The Main
class is defined in the ActionScript file called
Main.as. The project also contains a
package called example
.
Packages allow you to bundle classes together to facilitate code sharing. They also
allow control over the visibility of classes and method names outside the package by
using identifiers. This minimizes naming conflicts that can occur when developing
applications. We will use packages to hide the product classes from direct access by
clients in this example.
The example
package contains the Product1
and Product2
classes that implement the IProduct
interface. It also contains the
abstract class Creator
that is extended by two subclasses CreatorA
and
CreatorB
. Each class is defined in its own file, as is the convention with ActionScript 3.0. First, ...
No credit card required