Home
Username:
Password:
Adobe Flash ActionScript 3.0 for Designers Tutorials

Your First Script / Scripting Convention: Naming Rules

Subtitles of the Movie

Now that you've successfully written your first script let me now review some scripting conventions that you need to follow from here on out. Let's start off with naming rules. One of the most common beginner mistakes that I notice from my ActionScript students day in and day out can be traced to sloppy naming practices. Let me give you some rules to live by regarding naming your instances, frame labels, functions, variables, or any other name that you come up with during the course of your script work in Flash. You'll notice that all of these self-described or self-named elements are black here in the script. The blue words are reserved words and what you'll notice right away is that ActionScript 3.0 is case sensitive. Upper case letters matter and you'll quickly discover this when you forget to capitalize a required method name, for example, like MouseEvent right here. If I replace the capital E with a lower case E and then I do a Control, Test Movie you'll notice that I'll get an error in line 5, right there where I changed that capitalization. Also notice that my movie is looping, so none of the scripts are working. Also you'll notice that the color changed from blue to black. Let's go back and change that to a capital E and immediately the MouseEvent changes back to blue indicating that that is a recognized reserved word. Likewise, is gotoAndStop. All the capitalization must be followed or you'll break that method there. That should be a capital A. Again notice that as soon as I capitalize it, it changes from black to blue. So in order to reduce those annoying case errors never use upper case letters in your names, that way you'll never have to guess whether the function or instance name is handleClick with a capital C or without a capital C like this one right here. Now you will notice some instances of what they refer to as Camel Case in the scripts presented here. Some programmers like to use this Camel Case where you capitalize the second word of a compound word. I tend to use this usage, with no upper case letters, handle underscore click, but you will notice some of these Camel Case examples in the scripts presented. And again we do this to make these compound words easier to read, however, one thing that you will never see in the scripts presented are spaces in any of the labels. For example the page1 label has an underscore instead of a space there. The reason for that is Flash cannot parse those empty spaces. Instead it will substitute characters, usually a percentage sign like that to fill in that empty space thereby making your scripts unpredictable. The last thing you want to do is have this unpredictability when working with ActionScript, so instead what you want to do is use letters, spaces, or perhaps underscores, but never empty spaces in your names. In fact what I recommend that you do is use numbers 1 through 9 and letters a through z. Don't use any strange characters like pound signs, dollar signs, carats, ampersands and so on. Also never start your names with numbers. In many cases Flash will insist that your names start with letters. You can include numbers in your names, just don't start your names with numbers. And lastly, again, never include spaces in your names. So to summarize, do not use uppercase letters, Camel Case is OK. Underscores are also OK. Never use strange characters, use 1 through 9 and a through z. Always start names with a letter and never include spaces in your names. So if you follow these naming rules consistently and reliably I guarantee that you'll avoid a lot of potential problems and future errors and other mistakes when writing your ActionScript code.

Tutorial Information

Course: Adobe Flash ActionScript 3.0 for Designers
Author: James Gonzalez
SKU: 34060
ISBN: 1-935320-82-3
Release Date: 2009-11-09
Duration: 9.5 hrs / 101 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 81,350 Video Tutorials (20,800 free)
  • Video Available as Flash or QuickTime
  • Over 782 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available