Tutorial: Page (1) of 2 - 11/18/05 Email this story to a friend. email article Print this page (Article printing at MyDmn.com).print page facebook

ActionScript for Designers, Part 5

A (bitter?) pill we must swallow By Kevin Schmitt

Ed. note?previous installments of this series are available from the following links:

Part 1: We have to tear down before we rebuild
Part 2: Who's up for a little target practice?
Part 3: Nothing like a little detour after a really, really long break
Part 4: Targeting (and scripting!) the easy way

Believe it or not, we've come a long way. Fresh off our triumphant first script from last time, we're going to follow up today with a more casual discussion of such vague and jelly-like concepts as properties, operators, types, and functions. I'm going to try to make all this stuff as clear (and fun, if that's even possible) as I can, because although it's somewhat dry material, it's crucial stuff to (at least partially) grasp if you want to take the next step and start writing truly useful ActionScript.

Full disclosure time

Before we get going, let me take this opportunity to gently remind you that when it comes to "real" programming, I really don't have any idea what I'm talking about. You see, since this series is ActionScript for Designers and not ActionScript for People Who Have Computer Science Degrees and Already Program for a Living, I'm really not concerned with the fact that I have no formal training in programming at all. Like (what I hope is) the target audience of this series, I was, once upon a time, deathly afraid of anything even remotely related to programming. But necessity is the mother of invention, or in this case, it was the mother of getting off my duff and facing my fears and perceived lack of acumen for such things. Over time, and with no shortage of frustration, I got better, and so will you. But like the title character Jodie Foster played in Nell, I got comfortable with the language by coming up with my own ways of describing things to myself so that they made sense to me. So while I won't even begin to claim that I'm passing along best practices for programming in general (since I don't know what those are anyway), I will claim that the goal here is to augment your design skills with enough ActionScript understanding to allow you to conceptualize and execute some really nice interactive stuff in Flash all by your lonesome. If you want "true" programming lessons, by all means, look anywhere but here. Fair enough? OK, let's get on with it.

Cozy up to the Actions panel

The best way to try and put this highly geeky stuff into perspective is to go through and cherry-pick some of the concepts that would actually be of use to designers, with an eye towards starting with basic interactivity and then delving into things like procedural animation, fluid interfaces, video control, text manipulation, etc. So we're going to keep today's discussion firmly within the confines of the Actions Panel; specifically, the "Add a new item to the script" (the plus icon we've talked about in previous articles) button and what it contains.

So fire up Flash, open the Actions Panel, and point your mouse at the aforementioned "Add a new item..." button (fig. 1). Since that's where most of you will at least initially be starting scripts from, we're going to use that menu's hierarchy to help put things into a little bit of perspective. Don't let the contents of the menu scare you, because I have no qualms about skipping over stuff that should be ignored, at least for those just starting out with ActionScript.

Figure 1

So let's just go down the list, shall we?

1) Global Functions. Generally speaking, functions, unsurprisingly, represent functionality. In other words, these are commands that tell something to do something. Play. Stop. Print. Et cetera. This part of the menu lists functions that can be called at any time, hence the "global" tag.

Functions can also mean something else. You can create your own functions, effectively smushing complex code into a bite size handler that you define. For example, if I wanted to write a function that moved a Movie Clip to a certain set of coordinates on screen, I would write:

function moveClip(myClip, xCoord, yCoord) {
  myClip._x = xCoord;
  myClip._y = yCoord;

Then, to call the function and have it work on a clip named circle_mc (for instance), I would just write:

moveClip(circle_mc, 150, 150);

That would call the function I wrote and pass the name of the clip (circle_mc) and the x and y coordinates (150 and 150) as arguments. We're going to be writing functions later on in the series and going over what's happening in depth, but hopefully this is a clear enough introduction. So for now, just remember that a function tells Flash to do something.

Page: 1 2 Next Page

Related Keywords:actionscript, flash, flash 8, flash 8 professional


Our Privacy Policy --- @ Copyright, 2015 Digital Media Online, All Rights Reserved