sfmultimedia.net

sfmultimedia :: actionscript salons :: oop crash course

/

Object-Oriented Programming (OOP) Crash Course

This material was presented to the NBMA Web SIG on May 26, 2004. It was not an Actionscript Salon per se but the material is entirely relevant to anyone trying to improve their code-hacking abilities.

Do you get embarrassed when cocktail party conversation inevitably leads into Object-Oriented Programming? Having trouble understanding your child’s Flash-enabled website? OK, probably not, but I’m betting an awful lot of Flash designers have used gotoAndPlay(10) and on (release) to death and are ready to break out into something more powerful. Here it is.

There are simple things you can do to breathe new life into your Flash presentations, making them smaller, more efficient and hugely more interactive. During this presentation, we’ll gain a solid beginner’s understanding of what Object-Oriented Programming (OOP) really means and how ANYONE can apply its principles in Flash. We’ll do some coding on-the-fly, write some functions, extend some Objects, and really get to understand how we can use these tools to increase productivity, saving us time and money.

We might even have a laugh or two along the way.

Relevance/availability: The examples are written in Flash MX and AS1. So syntactically, these materials are a little out of date. That said, the presentation is still a good introduction to OOP for the designer or amateur programmer.

Presentation slides (swf)

Basic button action before functions. This is a simple button action as you (or someone you know) probably does it. The actions are on the buttons and we use gotoAndStop("labelname").

Download the .fla file (Zip 27k)

Basic button action with a function (1). The same functionality as the first example; only now the buttons are named and we assign the actions dynamically.

Download the .fla file (Zip 27k)

Basic button action with a function (2). Enhancing our previous example, we now call a function from each button. It's a pretty stupid function, mind you, but it shows the versatility inherent in calling a function (centralization, flexibility), rather than distributing code on various buttons and MovieClips throughout your fla.

Download the .fla file (Zip 32k)

Basic button action with a function (3). Click around and the pigeon zips where you click. Try doing that on a timeline! This example emplys three different functions. See if you can follow it through.

Download the .fla file (Zip 27k)

Flock of Pigeons. A fully-fledged Object. The Pigeon Object has a "private" method (init) for setting itself up, then several "public" methods...ie, methods meant to be accessible from outside the Object (what we refer to as its API). There are also some static properties to look at.

Download the .fla file (Zip 22k)

Download everything (flas with slides and swfs -- 204k)