O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Another Multiple-Type Example

In our earlier logging example, we learned that a class can inherit from another class while also implementing an interface. Instances of the subclass belong to both the superclass's datatype and the interface's datatype. For example, instances of the earlier LogUI class belonged to both the Sprite and LogRecipient datatypes because LogUI inherited from Sprite and implemented LogRecipient. Let's take a closer look at this important architectural structure with a new example.

Tip

The following discussion requires a prior knowledge of arrays (ordered lists of values), which we haven't covered yet. If you are new to arrays, you should skip this section for now and return to it after you have read Chapter 11.

Suppose we're creating an application that stores objects on a server via a server-side script. Each stored object's class is responsible for providing a method, serialize( ), that can return a string-representation of its instances. The string representation is used to reconstitute a given object from scratch.

One of the classes in the application is a simple Rectangle class with width, height, fillColor, and lineColor instance variables. To represent Rectangle objects as strings, the Rectangle class implements a serialize( ) method that returns a string of the following format:

"width=value|height=value|fillColor=value|lineColor=value"

To store a given Rectangle object on the server, we invoke serialize( ) on the object and send the resulting string to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required