
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Interface Syntax and Use
|
227
Thus, despite the fact that OrderUI extends MovieClip, OrderUI instances still
belong to the OrderListener type and can be passed safely to OrderProcessor.
addListener( ). (Wow, Ron, that’s amazing! It’s a pasta maker and a juicer!)
If OrderUI didn’t define a method named onOrderError( ), the compiler would gen-
erate the following error:
The class must implement method 'onOrderError' from interface
'OrderListener'.
Compiler errors are the key to the entire interface system. They guarantee that a class
lives up to its implementation promises, which allows external code to use it with the
confidence that it will behave as required. That confidence is particularly important
when designing an application that will be extended by another developer or used by
third parties.
Now that we have a general idea of what interfaces are and how they’re used, let’s
get down to some nitty-gritty syntax details.
The hypothetical order application just discussed is one example of
the delegation event model, which is covered in detail in Chapter 19.
Interface Syntax and Use
Recall that an interface is a construct used to define a new datatype without imple-
menting any of the methods supported by the datatype.
To create an interface in ActionScript 2.0, we use the interface keyword, ...