
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
ImageViewer Implementation (Take 1)
|
129
provide the target clip and depth as arguments to the constructor, so here is the new
constructor signature:
ImageViewer(target:MovieClip, depth:Number)
Code that uses the ImageViewer would now look like this:
var viewer:ImageViewer = new ImageViewer(someClip_mc, 1);
viewer.loadImage("someImage.jpg");
That code would create the ImageViewer instance, which would create a new empty
movie clip in
someClip_mc at depth 1. It would then load someImage.jpg into the
empty clip. Once loaded, someImage.jpg would automatically appear on screen
(assuming
someClip_mc were visible at the time).
The signatures and return datatypes of the constructor and loadImage( ) method in
our current class design now look like this (recall that constructor declarations never
include a return datatype):
ImageViewer(target:MovieClip, depth:Number)
ImageViewer.loadImage(URL:String):Void
That looks reasonably sensible. Only one way to find out: let’s code it up.
ImageViewer Implementation (Take 1)
Every ActionScript 2.0 class must reside in an external text file with the extension .as.
Hence, the first step in authoring our ImageViewer class is to create a text file named
ImageViewer.as. If you’re working in Flash MX Professional 2004, you can create and
edit ImageViewer.as using