
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Putting Theory into Practice
|
123
The following code shows how the Box class from Example 4-6 could be used on a
frame in a Flash document (.fla) timeline:
// Create a box 250 x 260 pixels, placed at coordinates
// (100, 110) in the current movie clip, on depth 1.
var b:Box = new Box(250, 260, 100, 110, this, 1);
After the Box instance is created, we can adjust its position and size as follows:
b.setX(400);
b.setY(400);
b.setWidth(10);
b.setHeight(20);
trace(b.getX( )); // Displays: 400
trace(b.getY( )); // Displays: 400
trace(b.getWidth( )); // Displays: 10
trace(b.getHeight( )); // Displays: 20
Putting Theory into Practice
Code, like art, is never really finished. You should explore your own ideas, even with
the simple Box class discussed in this chapter. Can you add code that randomly
places each Box instance on the Stage? Or changes the color of a Box instance? What
about code that rotates a Box instance or animates it along a straight line? Try add-
ing text fields on each box that display its
width, height, and area. You could even
make the text fields accept user input that can change the size of the Box.
You’ll gain insight into how to add these kinds of features in the next chapter, which
studies an ImageViewer class. This chapter covered a tremendous amount of techni-
cal ground in