Datasheet

the application to execute functionality that’s encapsulated within the class, without the program-
mer who’s calling the method having to know the details of how the action is actually executed.
For example, imagine a class that knows how to display a video in the Flash Player and allows the
developer to start, stop, and pause the video, and control the video’s audio volume. The code that
executes these functions would have to know lots about how video is handled in Flash and the
particular calls that would need to be made to make the audio louder or softer. The API of the
class, however, could be extremely simple, including methods to execute each of these actions.
public class VideoPlayer()
{
public function VideoPlayer(video:String):null
{ ... call video libraries to load a video ... }
public function start()
{ ... call video libraries to play the video ... }
public function stop()
{ ... call video libraries to stop the video ... }
public function setVolume(volume:int):null
{ ... call video libraries to reset the volume ... }
}
The application that instantiates and uses the class wouldn’t need to know any of the details; it just
needs to know how to call the methods:
var myVideoPlayer:VideoPlayer = new VideoPlayer(“myvideo.flv”);
myVideoPlayer.start();
myVideoPlayer.setVolume(1);
We say, then, that the VideoPlayer class encapsulates complex behavior, hiding the details of
the implementation from the rest of the application.
Inheritance
Inheritance refers to the ability of any class to extend any other class and thereby inherit that class’s
properties, methods, and so on. An inheritance model allows the developer to define classes with
certain members (properties, methods, and so on) and then to share those members with the
classes that extend them.
In an inheritance relationship, the class that already has the capabilities you want to inherit is
called the superclass, or base class, or parent class. The class that extends that class is known as the
subclass, or derived class, or child class. Unified Modeling Language (UML) is a standardized visual
language for visually describing class relationships and structures. In this book, I frequently use
UML diagrams such as the example in Figure 1.2 to describe how a class is built or its relationship
to other classes.
12
Flex Fundamentals
Part I
06_287644-ch01.qxp 6/23/08 11:28 PM Page 12