Where Do Scripts Go?

[ LiB ]

There are three places where scripts can be placed and written. If you remember the symbols we went over in Chapter 1, you'll recall that Movie Clips and buttons can contain ActionScript.

Buttons can contain attached scripts and do whatever helps your user navigate or control other parts of your program. Movie Clips can also contain scripts and morethey are one of the most flexible parts of the Flash program. What I mean by this is that you can attach scripts to Movie Clips and even attach scripts to its Timeline. You'll bump into each of these uses as we move on through the book.

In order to program components like buttons and Movie Clips, you must have somewhere to type. Flash has a nice built-in editor, called the Actions Panel, that you can use to type in your scripts. You can access this panel by selecting Actions from the Window menu, or by simply pressing F9.

Before you continue on to the next section, customize your Actions Panel for maximum flexibility. Start up Flash if it's not already open. Click on File, New, then press F9 to open the Actions Panel. It should look like Figure 3.1.

Figure 3.1. The Actions Panel


The panel in Figure 3.1 is set up in a quite antiquated style. What I mean by this is that the only way you can type in commands in the Timeline is by clicking on the commands that are listed in the pane on the left.

We won't be working in this mode for long, as it's extremely restrictive , but let's feel it out for a moment. Use the pane on the left to navigate to Actions, Movie Control, stop. Go ahead and double-click stop. The editor will add this action to the source pane on the right. Take a look at Figure 3.2 to see what your window should look like.

Figure 3.2. Insertion of the stop command


I have circled the elements in Figure 3.2 that you should notice in this exercise. First, the description of the command is briefly stated toward the top of the right side. Next, the command you clicked on is listed on the right. There are no options for the stop command, so it is one of the easiest commands that you will learn.

Meanwhile, in your main Timeline, you can see that you've made your mark (check out Figure 3.3). If you look closely at the first frame of the only layer there, you'll notice a little "a" over the hollow circle.

Figure 3.3. The "a" above the keyframe tells you there is a script in there.


Now, let's look at how to access commands another way. Right over your new stop command, you'll see a plus sign. Click on it and you should get a pop-up window similar to that in Figure 3.4.

Figure 3.4. A new way to access commands


After you click on the plus sign, you can navigate to the stop command in the same way you navigated with the command pane on the left. Just to catch a feel for it, go ahead and use it to navigate to the play command. It's under Actions, Movie Control, play.

You'll notice that the play command was added after your stop command. You'll also notice that they both end with opening and closing parentheses and a semi- colon . We'll go over this syntax shortly.



Syntax is a programming language's formatting rules.Think of it as the "grammar" of the language.

As I have just showed you, that left command pane is redundant; go ahead and remove it. Click on the arrow right on the divider within the Actions Panel (it's circled for you in Figure 3.5). The left command pane will close. Now you've got more room to work!

Figure 3.5. Collapsing the command pane


You have more room but you still don't have all the freedom that Flash can offer. The window is set up right now in Normal Mode, but you don't want to be merely normalyou want to be an expert. And to become an expert, you have to start thinking as such. You also need to be in Expert Mode.

So how do you switch to Expert Mode? Click on the View Options button over to the right side of your Actions Panel. You will get a pop-up that will have Normal Mode checked. Go ahead and click on Expert Mode. Use Figure 3.6 to locate the View Options button.

Figure 3.6. Switching to Expert Mode


The designers at Macromedia didn't think that one way to switch modes was enough, so they included a main pop-up menu on the Actions Panel that can allow you to switch modes and more. The button to access this menu is located on the top right. Check out Figure 3.7 to see where it is located.

Figure 3.7. The Actions Panel in Expert Mode




Future versions of Flash will only allow you to work in Expert Mode.There will be no such thing as "Normal Mode." In other words, the Expert Mode will be the normal mode.

In Figure 3.7, you can also see what Expert Mode allows you to do. It allows you to convert your click-and-insert window to a full-blown code editor. You can actually edit our two previously entered commands. But go ahead and delete them both. We won't need them at this time.

Notice that when you do delete these commands, the "a" over the keyframe disappears.

As far as the other mysterious buttons on the Actions Panelwhich should now be in Expert ModeI will be covering them when you need them. Right now, their functions will be useless to you.

The one thing you should keep handy is the ActionScript Reference from the Help file. There is a shortcut to the Reference on the Actions Panel. It looks like a little book with a question mark on it. I have circled it for you in Figure 3.8.

Figure 3.8. Accessing the ActionScript Reference


Once you have the Reference window open, you can find information and examples on any command that exists for the ActionScript language. Use it wisely. It's there for a very good reasonto help you write great code.

[ LiB ]

Game Development with ActionScript
Game Development with ActionScript
ISBN: 1592001106
EAN: 2147483647
Year: 2004
Pages: 162
Authors: Lewis Moronta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net