Tải bản đầy đủ (.pdf) (8 trang)

Tài liệu Using the Actions Panel/ActionScript Editor pptx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (19.53 KB, 8 trang )




< Day Day Up >

Using the Actions Panel/ActionScript Editor
Obviously, the premise of this book requires you to concentrate on writing scripts. It's a
good idea to get familiar with the tools you'll use in Flash to do so. In this, your first
exercise, you'll learn some of the basics of creating scripts with the ActionScript editor.
NOTE
The purpose of this book is to teach ActionScript, not so much how to use the Flash
interface. This discussion will be concise, providing enough information to help you
progress through the book. For a more extensive look at the many features of the Actions
panel, pick up the Macromedia Flash Visual QuickStart Guide.

1. With Flash open, choose File > New and choose Flash Document from the list of
choices. Press OK.
This step creates a new Flash document. It's usually a good idea to give your
document a name and save it, so we'll do that next.
2. From the File menu, choose Save As. In the dialog box that appears, navigate to
any folder on your hard drive where you would like to save this file (it's not
important where, really), name it myFirstFile.fla, and press the Save button.
After you press Save, the tab at the top of the document window will reflect the
name of your new file.
3. Open the Actions panel by choosing Window > Development Panels > Actions.
Let's look at the various sections of the Actions panel.

The Script pane is where you add ActionScript. You type into this window just as
you would a word processor. The script that appears in this window changes,
depending on the currently selected element in the Flash authoring environment.
For example, selecting a keyframe on Frame 10 allows you to place a script on


that frame if one doesn't already exist; if that frame already contains a script, it
will be displayed for editing.
The Actions toolbox contains a categorical list of ActionScript elements. Double-
clicking an icon (a book with an arrow) opens or closes a category in the list. The
toolbox is designed to provide a quick way of adding script elements to your
scripts for further configuration. You can add script elements to the Script pane by
double-clicking the element's name in the toolbox window, or by clicking and
dragging it to the Script pane.
The Script Navigator displays a hierarchical list of elements (frames, buttons,
movie clip instances) in your projects that contain scripts. Clicking an element will
display the script attached to it in the Script pane, allowing you to navigate quickly
through the scripts in your project for editing purposes. Only elements with scripts
attached to them appear in the Script Navigator.
The Script pane toolbar appears above the Script pane and provides a series of
buttons and commands, enabling you to add to or edit the current script in the
Script pane in various ways.
In the next steps, we'll explore the capabilities and functionalities of the
ActionScript editor. Let's look first at code hinting.
4. In the Script pane, type:
5.
6. myMovieClip_mc.
7.

NOTE
Let's assume this is the name of a movie clip instance we've placed in our movie.
Immediately after you type the dot (.), a drop-down menu provides a list of actions
applicable to movie clip instances.

Why did the editor provide a list of commands for movie clip instances? It's
because of the name we chose for our movie clip instance. Notice that we added

_mc to the movie clip instance's name. This suffix enables the editor to
automatically identify myMovieClip_mc as a movie clip instance and provide a
drop-down list of appropriate commands when you type that name in the Script
pane.
Common suffixes for visual movie elements include _btn for buttons and _txt for
text fields. We will be using these suffixes for visual elements throughout this
book.
Other, nonvisual elements, such as Sound and Date objects, have suffixes as well,
but instead of using suffixes for nonvisual elements, we'll instead be utilizing a
new functionality in Flash MX 2004, which we'll demonstrate next.
NOTE
For a complete list of suffixes, consult the ActionScript Dictionary.
5. Select the current script and delete it. In its place, type:
6.
7. var mySound:Sound = new Sound();
8.

This line of script creates a new Sound object named mySound. Creating a Sound
object using this syntax identifies mySound as a Sound object to the ActionScript
editor. As a result, referencing this object by its name later in the script will cause
a drop-down menu of appropriate Sound object–related commands to appear
automatically. Let's test it.
6. Press Enter/Return to go to the next line in the Script pane, and type:
7.
8. mySound.
9.

Once again, immediately after typing the dot, you see a drop-down menu with a
list of actions applicable to Sound objects.
You can create a new Sound object using this syntax:


mySound = new Sound();


but this syntax will not activate the functionality of code hinting when you script
that object, as the syntax in Step 5 does.
To help you grasp this concept, let's look at a couple more examples.
This code activates Color object–related code hinting for the myColor Color
object:

var myColor:Color = new Color();


This code does not:

myColor = new Color();


This code activates Date object–related code hinting for the myDate Date object:

var myDate:Date = new Date();


This code does not:

myDate = new Date();


NOTE
To clarify, in this book we will be using suffixes only when naming visual

elements such as movie clip instances, text fields, and buttons. This is because
visual elements are not created in the same manner as the description in this step.
Using suffixes in their names is the only way to activate code hinting when
referencing them in the ActionScript editor.
Let's look next at another type of code hint available in the ActionScript editor.
7. Select the current script and delete it. Type in its place:
8.
9. getURL(
10.

×