Fundamentals of Programming, part 1
Welcome, class.
You see, computer language is actually very similar to human language. But probably because computers are usually faster than humans, they like to take shortcuts.
Whereas you and I might say something like:
Robbie went to the beach yesterday.
ActionScript would say it like this:
robbie.go(beach,yesterday);
While it doesn’t make ActionScript sound like the most sociable character at the party, at least it’s concise. It might not look like much savings right now, but imagine writing an entire essay or short story. In the end, you’ll save yourself a lot of typing.
If you look a little more closely, you’ll see the parallels: we have a noun (object or class), a verb (method or function), and adverbs (parameters or arguments).
Understanding these basic concepts is the key to making sense of programming fundamentals. Unfortunately literal textbook definitions of these terms don’t really do much for people like designers, and that’s usually where most intro to ActionScript books spend the first chapter doing. That’s where most designers get lost. But I’ve found that comparing programming syntax to English grammar sets up a great metaphor for beginners. (As long as they speak English.) Don’t worry if you’re not a big fan of grammar, either. You’ll get a mini-refersher on the way.
Here’s a more practical example of something more akin to what you would actually write in ActionScript:
function animateBox() { //function
box_mc = new MovieClip(); // class, object
box_mc._x = 30 //property
box_mc.tween("_x", 30, 5); //method, parameters
}
Wouldn't it be great if you could understand what was going on here? We're going to take the individual components of this script and break it down for you, so that you understand the different parts.
CLASS = common noun
OBJECT or INSTANCE = proper noun
In the human world, a noun is a person, place, or thing. In ActionScript, the equivalent of that is a class or an object. But what’s the difference between a class and an object? It’s actually very similar to the difference between a common noun and a proper noun. If you remember grade school English well, you’ll recall that a common noun is usually uncapitalized and defines a general class (hint, hint, nudge, nudge) of people, places, or things whereas a proper noun is usually capitalized, and describes a specific, unique person, place, or thing. In ActionScript, a class is like a common noun and an object is like a proper noun. Let’s look at some examples:
| city | Boston |
| dog | Lassie |
Movie Clip |
box_mc |
Sound |
leftChannel_sound |
One thing to keep in mind is that in English grammar, we capitalize our proper nouns (objects) and lowercase our common nouns (classes), but in ActionScript, we do the exact opposite: we capitalize classes (common nouns) and lowercase objects (proper nouns).
METHOD = verb
In English, verbs describe actions that nouns can do. In ActionScript, methods describe what classes/objects can do. A method always belongs to a certain class, just like verbs must be associated with some sort of noun.
For example, humans can talk while birds can fly, so in ActionScript, we’d say that the talk() method belongs to the Human class, while the fly() method belongs to the Bird class.
FUNCTION = paragraph
Just like we were taught to group separate ideas into separate paragraphs, similarly, in ActionScript, we group blocks of code that serve separate duties into separate functions.
PROPERTY = adjective
Remember when your middle school English teacher would give you back your short stories begging you, in red ink no less, to spice them up by using more adjectives to describe your nouns? Properties do the same thing for objects.
PARAMETER or ARGUMENT = adverb
And just as adjectives modify nouns, it’s the adverb that modifies the verb — the equivalent of the adverb in ActionScript is the parameter (also known as “argument").
VARIABLE = blank
This is usually the first thing that ActionScript/Programming books go into explaining. But designers have a difficult time understanding just exactly what a variable is because it's such an abstract concept, which makes it difficult to draw a visual metaphor for it. I remember learning that all I had to understand was that a variable is essentially a "container for data." Mmm...okaaay.
CUSTOM FUNCTION = ad lib
About this entry
You’re currently reading “Fundamentals of Programming, part 1,” an entry on ActionScript for the Pissed-Off Designer
- Published:
- 04.11.08 / 7pm
- Category:
- Fundamentals of Programming
No comments
Jump to comment form | trackback uri