
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
146
|
Chapter 5: Authoring an ActionScript 2.0 Class
How would ImageViewer version 2 respond to being constructed with only two
parameters? Fortunately, very well. Version 2 specifically safeguards against missing
parameters. The createImageClipMask( ) and createBorder( ) methods create the
mask and border clips only if a useful width and height are supplied, as shown in this
excerpt from Example 5-5:
if (!(w > 0 && h > 0)) {
return;
}
Thus, when no width and height are supplied to the constructor, ImageViewer ver-
sion 2’s behavior matches ImageViewer version 1’s behavior exactly.
After a class is formally released, upgrading to a new version should
not break code that uses the old version. Changes to the class itself
should not force changes to code that merely uses the class. One way
to achieve this is for the new class to assume reasonable default behav-
ior if some arguments are not supplied.
ImageViewer Implementation (Take 3)
Let’s review the potential functional requirements for the ImageViewer class:
• Load an image
• Display an image
• Crop an image to a particular rectangular “view region”
• Display a border around the image
• Display image load progress
• Reposition the view region
• Resize the view region
• Pan (reposition) the image within the view region
• Zoom (resize) the image ...