
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Logger: A Complete Observer Example
|
363
Now let’s look at our log’s other observer class, TextFieldView.
The TextFieldView Class
The TextFieldView class displays log messages in a text field in the Flash movie
rather than in the Output panel.
The basic structure of TextFieldView is identical to OutputPanelView. Like
OutputPanelView, TextFieldView defines a
log property and an update( ) method. It
also adds a new method, makeTextField( ), which creates an on-screen TextField
instance in which to display messages. And it adds a new property,
out, which stores
a reference to the text field created by makeTextField( ). The TextFieldView construc-
tor defines seven parameters:
l
A reference to the Logger instance that will be observed
target
The movie clip in which to create the text field
/**
* An observer of the Logger class. When a movie is played in
* the Flash authoring tool's Test Movie mode, this class displays
* log messages in the Output panel.
*/
class logger.OutputPanelView implements Observer {
// The log (subject) that this object is observing.
private var log:Logger;
/**
* Constructor
*/
public function OutputPanelView (l:Logger) {
log = l;
}
/**
* Invoked when the log changes. For details, see the
* Observer interface.
*/
public function update (o:Observable, infoObj:Object):Void ...