
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
218
|
Chapter 7: Authoring an ActionScript 2.0 Subclass
and finally, we reassign the new mask movie clip (mask_mc) as a mask over the image
movie clip (
image_mc):
container_mc.image_mc.setMask(container_mc.mask_mc);
The setSize( ) method gives a good sense of the convenience and logic of OOP. Every
class offers a set of services; other classes can use those services to build new func-
tionality. In setSize( ), most of the work involves simply invoking methods that
already exist in the ImageViewer class.
Example 7-2 shows the updated code for the ImageViewerDeluxe class. Enter the
new code, shown in bold, into your ImageViewerDeluxe.as file.
Autosizing the Image Viewer
Well, that was so easy we may as well have a little more fun. Now that our
ImageViewerDeluxe class supports resizing, let’s add the ability to automatically
resize the viewer to fit the size of any loaded image.
To set the size of the viewer when an image loads, we’ll override the ImageViewer
class’s onLoadInit( ) method. From the ImageViewerDeluxe version of the method,
we’ll check the size of the loaded image and then use our handy new setSize( )
Example 7-2. The ImageViewerDeluxe class with reposition and resize features
/**
* An ImageViewer subclass that adds reposition and resize features
*/
class ImageViewerDeluxe extends ...