Beginners OOP & Design Patterns in ActionScript 3.0 Post 1 : Rolls-Royces in the Junk Yard

Beautiful algorithms can be isolated in a trashy structure
Beginning Where You are Now
This is the first in a series of posts that look at working with ActionScript 3.0 using Object Oriented Programming (OOP) methods and Design Patterns for those beginning OOP. I had been programming for a very long time before I got involved with OOP and Design Patterns and then I more or less dove into both at the same time. Here are some assumptions I’m making about those of you who are reading this:
- You’re using ActionScript 3.0 with either Flash Builder (FB) or Flash Professional (FP).
- You know how to write a program that does something in ActionScript 3.0 beyond snippets on the timeline
- You know what an algorithm is and know how to write at least some in ActionScript 3.0.
- You’re devilishly handsome or jaw dropping beautiful.
This is not a tutorial about how to use Flash Builder or Flash; so if you’re trying to learn Flash/Flex, this tutorial probably is not too helpful except for writing ActionScript 3.0.
The amount of time you’ve been programming is not that important for getting started with this series. The line of demarcation between OOP and Non-OOP programming is quite clear, and this series is about crossing that line; not how long you’ve been on the Non-OOP side. Throughout this series, you will be linked to other posts from this blog for details on one point or another. This series itself is action-oriented in that we’ll be looking at code that you can enter and use to understand OOP and Design Patterns. A lot of the conceptual discussions will be in the linked posts. Your first link is to this Starter Kit. You’ll find other beginner links in that post along with tools you can put on your desktop to help you when you’re writing code.
The Object in OOP
The terms “object” and “class” are almost interchangeable. Following convention, I’ll be referring to an object as instance of a class. In many respects, crossing the line is simply a matter of using classes. In order to see the line-crossing, let’s begin with an example on the sequential side of the line. The following program exemplifies sequential programming. You’ll need a graphic file, so download the one provided (Inspecting OOP) in the post—you’ll see it further on in this post. In Flash, just select the first keyframe on the timeline, open the Actions Panel and dump in the following script:
1 2 3 4 5 6 | var pic:String="inspect.png"; var loader:Loader=new Loader(); var loadUp:URLRequest=new URLRequest(pic); loader.x=150, loader.y=50; loader.load(loadUp); addChild(loader); |
When you test it you should see your graphic appear. If that worked out ok, take the program, and the Actions Panel to the back yard. Dig a hole and bury them. You’ll never being using that kind of programming again.
A Quick and Dirty Run Through Flash Builder
Some of the comments we’ve received have indicated that it would be helpful to take a step-by-step trip through Flash Builder to see how to get the ActionScript 3.0 design patterns created. So you might want skip this section if you’re using Flash Professional or if you’re an old hand developing ActionScript 3.0 using Flash Builder.
- Open Flash Builder (FB) and select New -> ActionScript Project from the File menu.
- When you open the New ActionScript Project window, you will see the page shown in Figure 1. Name the project Beginners1 (in the Project name window) and then click the Next button.
- The next window you see has most of the information filled in for you. However, in the Main application file window change the default name to Client.as as shown in Figure 2. Once you’ve made the name change, click the Finish button.

Figure 1: Adding Project Name

Figure 2: Indicating the main application file name
Now you should be all set to write your ActionScript 3.0 in Flash Builder. However, you need to place your 250 x 250 file in the bin-debug folder. You can download the one I used sitting on the right side of your screen below. (Or click below for the rest of the post if you cannot see the graphic image.)
Read more…
Monday we’ll start a new series for beginners in OOP and Design Patterns using ActionScript 3.0. The series will include examples from both Flex (Flash Builder) and Flash (Flash Professional.) The vote wasn’t even close, but because we believe that concurrent programming (parallel programming, multi-threaded programming) is so crucial to the future of both ActionScript 3.0 and programming in general, we’ll be issuing posts on those as well. In the same polling, there were requests for combo patterns, frameworks, and even one for MVC, but for the time being, we’ll be developing a series for beginners and I’d like to make a run at creating a virtual machine for doing concurrent programming in ActionScript.







Bill Sanders
Recent Comments