Object-Oriented Actionscript for Flash 8 overflows with knowledge

When I picked up Object-Oriented Actionscript for Flash 8, I kept my expectations neutral. I’ve said it before, but it’s important to note, I hate programming books. They’re either too dry or too basic. Thankfully, Peter Elst and Todd Yard kept things interesting in early chapters, and their writing flowed smoothly to help keep me interested as they added on each new layer of information. Coming in at 540 pages, this mighty tome is one of the thickest Flash books on my bookshelf. I don’t own the printed version of the Actionscript 2 Language Reference myself, but it might be the only one that’s bigger.

The first chapter, “Introduction to OOP“, contains the best explanation of objects and classes that I’ve heard yet. If you’re thinking that it’s time to move on from timeline code to classes, this chapter alone should help the most in getting you started. The writers keep it short and sweet, yet these eight pages contain many great diagrams and analogies to ease you into core concepts including encapsulation, inheritance, and polymorphism. It’s so simple to visualize things like a blueprint (class) being used to create a house (object), or the fact that cars from two different companies, such as Volkswagen and Toyota, can both be started by turning a key (inheritance and interfaces). To keep the reader in a programming mindset, a few lines of pseudo-code help to reinforce each new concept.

In the next couple of chapters, the authors introduce basic programming concepts and the Actionscript 2 language. This section goes by very quickly, and if you’re just getting started, you might want to read it over a couple of times. It seems to me that the authors pretty much assume that you’ve already done a bit of programming and you’re really looking to move on to the next. If you’re coming from a different language, like Java, it’s perfect because you can easily skim to each example of syntax. I like that a lot. Everytime I pick up a book to learn a new language, I hate reading through half a dozen chapters that assume that I’ve never heard of a compiler or a variable.

Chapter 4 presents ways to plan a programming project. The reader learns about different projects phases and how to use UML to represent classes and their relationships. Chapter 5 introduces workflow tools like version control systems (like CVS or Subversion), programming appearches like RAD and Extreme Programming, and a short section on usability. The final chapter in this section goes over some of the authors’ personal best practices. They present different ways to format code, reasons for using comments, and good naming schemes for variables and functions.

With the basics out of the way, the authors begin showing real Actionscript examples of those core programming concepts covered in the first chapter. We start out with some basic encapsulation that seperates different actions into functions. As the first bit of real code, the example of a ball moving on the stage is represented in timeline code. Personally, I would have liked to see the authors just move straight into classes, but this example is a good way to get a beginner started and to keep things familiar for Flash users that are already used to the timeline.

With the ball now rolling (bad pun), the authors start implementing their first classes. Like functions, classes offer another way to encapsulate functionality. Additional parts of classes like constructors, member variables and methods give the reader his or her first taste of what’s in store. Again, examples with real-world objects, like cars, help illustrate how classes work. The “Mover” class at the end of this chapter brings the earlier ball example into the modern Flash world, and it lays the groundwork for additional expansion in the next couple of chapters. With Mover implemented, the authors tackle inheritance by creating a Bouncer class with specialized functionality and a Gravity class to help reinforce the idea.

A short chapter on polymorphism goes on a bit of a tangent. Elst and Yard move away from the Mover classes, and polymorphism is presented differently. First, the basics are explained using body states such as hunger, boredom, and tiredness. It’s interesting to see the idea of interfaces shown without them actually being introduced yet. That happens in the next chapter. I almost wonder if perhaps these examples should have been used earlier. The reader may consider it a nice break from the coding, or it may be confusing. I can’t accurately judge that since I’m already well versed in this concept. When interfaces are truly introduced, we jump back into the Mover project and implement IMovable, IBounceable, and IGravity. With the previous movement classes, the code changes very little to include the interfaces. I always have trouble with chapters on interfaces. I believe that many seasoned programmers don’t always know when interfaces are needed, and I wish programming books would show better use-cases. It’s not specific to this book, just something that I’d like to see in more OOP books and tutorials.

The authors near the end of the first half with their introduction to design patterns. Patterns offer great, tested solutions to programming problems. They’re like frameworks that help you build your projects quicker, and they help you and others maintain your code more easily. Personally, I’m still learning patterns, so I found this chapter especially useful. Unfortunately, if you’ve already learned a bit about common patterns used by Flash developers, such as MVC, Singletons, Decorators, and Observer, you might not pick up much addtional knowledge. I could be wrong, but I believe that Colin Moock’s Essential Actionscript 2.0 covers the exact same patterns. Many folks highly recommend that book, so if you have trouble with this section, consider picking it up to hear a different author’s perspective on the subject.

The first half draws to a close with a case study that uses all of the techniques covered in earlier chapters. The authors create an OOP-based Media Player that can load Flash SWFs, Video, and MP3 files. By combining design patterns, some of the classes created earlier, and all sorts of great new examples of classes and inheritance, the authors do a wonderful job of bringing everything full-circle. There’s a good deal of code presented in this chapter, but each section includes a specific explanation. If you’re just learning these concepts, I highly recommend running through this whole example in Flash to get it working. The best way to learn is to just jump in and do it.

In any other Actionscript book, I’d expect to have reached the end. However, Peter Elst and Todd Yard truly go the extra mile. The first half is mainly geared toward AS2 beginners, but the second half bursts with knowedge aimed at more advanced developers. Stay tuned for part two of my review on Object-Oriented Actionscript for Flash 8 where the authors create a framework and present chapters on some of Flash’s included classes and features that you may not even know about.

About Josh Tynjala

Josh Tynjala is a frontend developer, open source contributor, bowler hat enthusiast, and karaoke addict. You might be familiar with his project, Feathers UI, an open source user interface library for Starling Framework that is included in the Adobe Gaming SDK.

Discussion

  1. Savvas

    This is an amazing book.
    I start studing OOP with this book and finally i start to “get on it”..
    Thanks guys..

  2. Jason Fincanon

    I bought the book a few months or so ago and I’ve finally got enough time to start reading it. *How far I’ll be able to get into it before I get swamped again is anyone’s guess.* Thanks for the post about it!

  3. Abdul Qabiz

    Hi,

    I am yet to write my views on the book, lately very busy. Since you have posted in similar context, I have an opportunity to say on it.

    I would highly recommend people specially who want to learn OO development in ActionScript. I would surely write more about it on my blog..

    Indeed, Thanks to Peter and Todd for writing this book..

    cheers

    -abdul

  4. William from Lagos

    Hey Josh,

    Nice review of the book. I actually bought the book a month ago, but haven’t had time to read it properly, because of work and other pending projects.

    Another thing that seems to discourage me (somewhat) is Flex and Actionscript 3. Flex is really the buzzword out there and in my perspective, Actionscript 3 is a different compared to Actionscript 2. So sometimes when I pick up the book and want to read it, I ask myself, “Why do you want to spend time still learning OOP in Actionscript 2, when I can start learning OOP in Actionscript 3 (and indeed Flex)?”

    I would appreciate any answer and advice at all, cause I really want a concrete reason to read this book.

    This is basically my perspective, being a Flash and RIA developer.

    Cheers!

  5. Josh Tynjala

    William,

    Don’t let Flex 2 and AS3 discourage you from reading this book. It doesn’t matter what language you use to learn OOP, the knowledge will be beneficial no matter where you take it. You could read a book about OOP for Java or C# and still be able to use what you’ve learned with the next generation of Flash.

  6. Pingback: Object-Oriented Actionscript for Flash 8 overflows with knowledge (Part 2) » Zeus Labs