Sei sulla pagina 1di 39

1637-X cover 5/6/02 12:25 PM Page 1

Perfect Bind Trim: 7 3/8 x 9 1/4 Bleed: .25 4 color process UV Gloss spine = .816

Build animated buttons,


e p ower o f Ac tionScript
shopping carts, ActionScript Harness th ience required!
exper
no programming
tutorial lessons
on CD-ROM
jukeboxes, and more!

Flash MX ActionScript
For more
plain-English
Macromedia
advice, see:
ctionScript
Flash MX A


Macromedia
Turn your creations into
awesome interactive applications
just add ActionScript!
ActionScript lets you take Macromedia Flash MX to a new level of
interactivity. But how do you get the hang of all those objects, functions,
operators, and new enhancements? Dont worry! With the tips and
tutorials in this friendly reference, youll be creating mouse chasers,
scrolling text blocks, and online quiz games in no time.

Doug Sahlin, a digital artist and Web designer, is the author of


Macromedia Flash MX ActionScript for Designers, Fireworks 4 For Dummies,
and many articles on 2D and 3D graphics.
ActionScript
tutorial lessons,
ActionScript tuto
rial lessons, artw
ork,
en t
artwork, sound files
files, bonus co nt
and more on
examples, sound
and more
@
A Reference CD-ROM
Demo versions of
ActionScript tool
s,
d
 Find listings of all our books for the
including SW fX fo
Swift 3D for creati
r animated text an
ng 3D objects
 Create your own
personalized book with
Hungry Minds a la Carte
Rest of Us!
FREE daily eTips at dummies.com
Power Macintosh
dows 98 or later;
System requireme
nts: PC running Win
or later. See the About the CD appendix for det
ails and
 Sign up for daily eTips at
running System 9.1 .
complete system
requireme nts
www.dummiesdaily.com

ISBN 0-7645-1637-X

Doug Sahlin
*85 5 -BAF Bf ,!7IA7G4-fbgdhf!:p;M;t;t;T
$29.99 US
$44.99 CN Author of Macromedia Flash MX
23.99 UK incl. VAT
ActionScript for Designers

Web Development Sahlin


1637-X BC01.F 5/9/02 3:12 PM Page CD-1

Bonus Chapter 1

Actions Dictionary
T heres lots of stuff lurking under the hood of the Actions panel. The panel
is named actions, even though some of the things in the Actions panel are
actually properties or functions. But they all cause some sort of action to
happen when you add them to an ActionScript so I guess the name is okay.
In this appendix I show you how to work with the most commonly used
Actions youll find in the Actions panel. Who said that?

The Actions panels got lots of books. And some of these books have books
within a book. To add some actions to your scripts, you have to click this
book icon, then click that book icon, then click another book icon, and so on.
Rather than bore you with a lot of words, Im going to show the path to each
action as shown in the following example: Click ActionsMovie Control and
then double-click goto.

Movie Control
The path to this book is ActionsMovie Control. The actions in this book are
well, fairly basic, but they are often the rudder that steers an ActionScript
movie. In the following section, I show you some of the common Movie
Control actions and examples of how to use them in your Flash movies.

goto
You use this action to navigate to a specific frame within the current scene or
another scene. You can also use this action to go to a specific frame within
a movie clip by addressing the movie clips target path and then adding the
goto action. This action has three parameters that you specify: Scene, Type,
and Frame. There are also radio buttons that you use to have the action go to
and play a frame or go to and stop at a frame. Following are two examples of
the action in action. In the first example when the action executes, the movie
advances to frame 1 in Scene 1 and stops. In the second example, the movie
advances to a frame labeled beginScene and plays.

gotoAndStop (Scene 1, 1);


gotoAndPlay (beginScene);+
1637-X BC01.F 5/9/02 3:12 PM Page CD-2

CD-2 Macromedia Flash ActionScript MX For Dummies

on
The on action occurs automatically with the default release event when you
assign an action to a button. You can always insert it manually by choosing
the action directly from the Movie Control book. You have eight events to
choose from. More than one mouse event can be assigned to a button. In the
following example, the movie advances to a frame labeled guessNumber
when the button the action is assigned to is released. The first line of code
is the mouse event; the second is the action that occurs when the mouse
event happens.

on (release) {
gotoAndPlay (guessNumber);
}

For more information on this action, refer to Chapter 11.

play
You use this action to resume play in a movie that has been halted.
The action has no parameters.

play();

stop
You use this action to stop a movie. This action has no parameters.

stop();

stopAllSounds
This action stops all sounds in a movie except for looping sounds that stop
when the movie reaches the keyframe that the stopAllSounds action is
assigned to. The sounds begin again when the movie loops back to the
first frame.

stopAllSounds ();
1637-X BC01.F 5/9/02 3:12 PM Page CD-3

Bonus Chapter 1: Actions Dictionary CD-3

Browser/Network
The path to the Browser/Network book of actions is ActionsBrowser/
Network. You use the actions in this book to navigate to URLs, load and
unload movies into your Flash movie, and to load variables into a movie.
Youll use these actions repeatedly in your work. The loadVariables
action is a real time-saver.

getURL
You use this action to advance the movie to another URL. The action has
three parameters: URL, Window, and Variables. The following example
opens up a Web site in a different window.

getURL (dasdesigns.net);

For more information on the getURL action, see Chapter 4.

loadMovie
You use this action to load a movie from an external source into the current
movie. The action has three parameters: URL, Location, and Variables. The
following example shows a line of code that loads a movie into level 1.

loadMovieNum (about.swf, 1);

For more information on the loadMovie action, see Chapter 5.

loadVariables
The loadVariables action is used to load variables such as a text file from
an external source. The action has three parameters: URL, Location, and
Variables. The following example shows the action being used to load a file
named text.txt into level 0.

loadVariablesNum (text.txt, 0);

For more information on loading variables, see Chapter 10.


1637-X BC01.F 5/9/02 3:12 PM Page CD-4

CD-4 Macromedia Flash ActionScript MX For Dummies

unloadMovie
You use the unloadMovie action to unload a previously loaded movie. The
action has one parameter: Location. The following example unloads a movie
from level 1.

unloadMovieNum (1);

For more information on the unloadMovie action, see Chapter 5.

Movie Clip Control


The path to the book youll use to control the actions of your movie clips is
ActionsMovie Clip Control. If you need to control a movie clip thats run
rampant, grab it by the scruff of the neck. . . . But seriously, to control a
movie clip, you use actions from this book. If you want 50 movie clips where
there once was one, the action you need waits patiently in this book for
you to add it to a script.

duplicateMovieClip
You use the duplicateMovieClip action to clone movie clips. The action
has three parameters: Target, New Name, and Depth; where Target is the orig-
inal movie clip, New Name is the name youre assigning the cloned clip, and
Depth is the number of clones youre creating. The following example shows
a movie clip that is duplicated with a loop. In this example, the action creates
as many movie clips as the maximum value of the variable, counter. The
cloned clips will be named starz1, starz2, and so on.

duplicateMovieClip (starz, starz+counter, counter);

For the lowdown on duplicating movie clips, check out Chapter 9.

onClipEvent
The onClipEvent action is an event handler for a movie clip. The action
with its default on (Load) event is added to a script any time you assign
an action to a movie clip. You can also use the action manually by choosing
the onClipEvent action in the Actions panel. How the action is executed
1637-X BC01.F 5/9/02 3:12 PM Page CD-5

Bonus Chapter 1: Actions Dictionary CD-5


depends on the event handler you choose. In the following example, a movie
clip called myClip can be dragged when the user clicks his or her mouse
over the movie clip.

onClipEvent (mouseDown) {
startDrag (_root.myClip);
}

For more information on this action and working with movie clips, refer to
Chapter 9.

removeMovieClip
This action removes a previously duplicated movie clip. The action has one
parameter: Target.

setProperty
You use the setProperty action to set a property of a movie clip, such as its
location, size, and so on. The action has three parameters: Property, Target,
and Value. The following example shows the x position of a movie clip being
changed to 350.

setProperty (myclip, _x, 350);

If you need more information about working with properties, refer to Chapter 7.

startDrag
You use the startDrag action on a movie clip. When the action is executed,
the viewer of the movie can drag the movie clip. The action has one parame-
ter, Target, and two options that you use to constrain the motion of the movie
clip and/or lock the movie clip to the mouse center as it is being dragged.
In the following example when the action is executed, a movie clip called
gamePiece can be dragged and will be locked to the mouse center while
being constrained to a motion of 100 pixels.

startDrag (gamePiece, true, 0 , 0, 100, 0);

For more information on how to create a movie clip thats kind of a drag, refer
to Chapter 11.
1637-X BC01.F 5/9/02 3:12 PM Page CD-6

CD-6 Macromedia Flash ActionScript MX For Dummies

Variables
The path to everything you could possibly need to do with variables is
ActionsVariables. The actions in this book create things that vary. In other
words, if you need to create a variable, this is the place to get your action.

set variable
You use the set variable action to declare a variable. A variable is a place-
holder for data. In essence, variables give Flash the capability to remember
data. The following example shows the action being used to declare a vari-
able named message with value of Thank you for your order. When you
see a variables value surrounded by quotation marks, it is string data.

message = Thank you for your order.;

For more information on working with things that vary (like variables), refer
to Chapter 6.

with
You use the with action when you want Flash to perform a certain action
with something, say a labeled instance of a movie clip or one of the Flash
ActionScript objects. The following example shows the action being used
in conjunction with a button. When the button is pressed, Flash will go to
and play frame 2 of (or more aptly with) a movie clip called myMC.

on (press) {
with (_root.myMC) {gotoAndPlay (2);
}

Conditions/Loops
The path to the Conditions/Loops book is ActionsConditions/Loops.
Remember when you were a kid and your mother told you not to do some-
thing under no uncertain terms, which of course you did and received a stern
scolding for it? Well, that was a condition, which you evaluated as being false,
which is why you did what you were told not to. Next week you went out and
did it again. Dj vu. You got scolded again. But you continue to do it over
and over again. Thats a lot like a loop. And when your father stepped into
the picture wielding a heavy hand, that broke the loop.
1637-X BC01.F 5/9/02 3:12 PM Page CD-7

Bonus Chapter 1: Actions Dictionary CD-7

else
This action follows an if action. If the condition evaluated by the if state-
ment is false, the action following the else action will execute. In the following
example, as long as the value of lives is greater than 0, Flash will go to and
play frame 2. The alternative is designated by the else action. As soon as
the value of lives equals 0, the condition in the If statement is false and
the line of code following else action occurs.

if (lives>0) {
gotoAndPlay (2);
} else {
gotoAndPlay (4);
}

For more information on the if, else, and else if trilogy, check out
Chapter 12.

else if
You use the else if action when the condition in an if statement has multi-
ple outcomes. In the following example, the value of the greeting changes
depending upon the time of day.

if (current_time<6) {
greeting = Good evening,;
} else if (current_time<12) {
greeting = Good morning,;
} else if (current_time<18) {
greeting = Good afternoon,;
} else {
greeting = Good evening,;
}

For more information on the if, else, and else if trilogy, check out
Chapter 12.

if
The if action is used to evaluate a conditional statement. If the statement is
true, the next action is executed. If the statement is not true, the last action in
1637-X BC01.F 5/9/02 3:12 PM Page CD-8

CD-8 Macromedia Flash ActionScript MX For Dummies

the script will execute. The if action is often used with the else or else if
actions. In the following example, if the statement in parentheses evaluates
as true, the movie will advance to and play frame 5.

if (tries==0) {
gotoAndPlay (5);

For more information on the if, else, and else if trilogy, check out
Chapter 12.

for
This action is used to create a loop where you know exactly how many itera-
tions of the loop will occur. The action has three parameters: Init (the initial
value of the variable being used as the counter), Condition (the condition
that must be true for the loop to continue), and Next (the increment for the
counter). The following example shows the counter as a variable i with an
initial value of 0. As long as i is less than or equal to 4, the loop will continue.
The counter increments by a value of 1 as shown by the third statement in
parentheses, i++.

for (i=0; i<=4; i++)

For more information on this action, refer to Chapter 5.

Printing
The path to the Printing actions book is ActionsPrinting, although for the
life of me, I dont know why this has its own book theres only one action
in there. Perhaps there will be more in the future, but for now, the following
action is all you get.

print
You use this action when you want to turn a frame in your movie into some-
thing the user can print out with his or her own printer. The action has three
parameters: Print, Location, and Bounding. The following example shows a
print action assigned to a button. When the button is released, the bounding
area for the frame will be printed.

on (release) {
printNum (0, bmovie);
}
1637-X BC01.F 5/9/02 3:12 PM Page CD-9

Bonus Chapter 1: Actions Dictionary CD-9


For more information about creating printable frames, check out Chapter 14.

User Defined Functions


The path to this book is ActionsUser Defined Functions. Flash has a lot of
perfectly good functions, but sometimes you need more. When you do, this
is the book you get it in.

call
You use the call action to apply ActionScript from another keyframe to the
keyframe you assign the call action to. The call action literally calls the code
from another keyframe. This action has one parameter: Frame.

call (checkOut);

Miscellaneous Actions
The path to this book is ActionsMiscellaneous Actions. Although these
actions may be miscellaneous in the eyes of the geeks who created Flash,
theyre very useful. Hmm . . . that reminds me of my old grade-school teacher,
Miss C. Laneous.

comment
You use the comment action to add messages to your ActionScript. The mes-
sages you add can be notes for yourself on what the ActionScript is doing or
notes to other designers working on the project. A comments text is colored
light gray and is always preceded by two forward slashes (//). The action
has one parameter: Comment.

// This line of code increases the value of the variable by


1.

For more info on this action, refer to Chapter 3.


1637-X BC01.F 5/9/02 3:12 PM Page CD-10

CD-10 Macromedia Flash ActionScript MX For Dummies

evaluate
You use the evaluate action to create an expression for Flash to evaluate.
The action has one parameter: Expression. The following example shows
an expression created with the evaluate action.

_root.sexysadie.gotoAndPlay(2);

trace
You use the trace action to keep track of what is happening at a certain
point in your movie. You can use the action to trace the value of a variable
or to display a message. The value or message is displayed in the Output
window when you test the movie. The following example shows the action
tracing the value of a variable named totalValue.

trace (totalValue);

For more information on this action and dealing with buggy ActionScript,
refer to Chapter 13.
1637-X BC02.F 5/9/02 3:12 PM Page CD-11

Bonus Chapter 2

ActionScript Properties
Dictionary
T he topic of discussion near and dear to this here appendix is an objects
properties. Every object has properties; for example, its size, its position
on stage, and its visibility. In the following sections, I show you how to work
with what I consider the most important properties in Flash.

Note: This is one of those rare action books that has no sub-books. All youve
got to do is open the Actions panel, click the Properties book icon, and you
can use all the following goodies in your ActionScript.

alpha
When you change an objects alpha property, you vary the objects opacity,
which lets more of the underlying objects show through. The following exam-
ple shows the alpha property of a movie clip named myMC being changed to
50 percent.

_root.myMC._alpha=50

framesloaded
This property returns the total number of frames of the movie clip that have
loaded, or if you specify the root timeline, the number of frames in the base
movie that have loaded. You can use this property as part of an equation
that determines the percentage of the movie that has loaded.
1637-X BC02.F 5/9/02 3:12 PM Page CD-12

CD-12 Macromedia Flash ActionScript MX For Dummies

rotation
This property returns the current rotation of a movie clip object. You can
also use this property to set an objects rotation. In the example shown here,
the rotation of a movie clip named spaceShip is being set to 45 degrees.

_root.spaceShip._rotation=45;

total frames
This property returns the total number of frames in the movie clip, or if the
root timeline is specified, the total number of frames in the movie. You can use
this property to set up an equation that returns the percentage of a movie that
has loaded. In the following example, a variable called percentLoaded is cal-
culated using the totalframes and framesloaded properties.

percentLoaded = (_root._framesloaded/_root._totalframes)*100;

visible
You use this property to determine whether an object is visible or not. This
property is Boolean, the object can either be seen or not. In the example shown
here, the object is not visible. Note that when you use this property (as with
other Boolean expressions), you can substitute 0 for false and 1 for true.

_root.spaceShip._visible=false;

_x
This property returns the x position of an object. In the following example,
the x coordinate of a movie clip instances named spaceShip is being
changed to 350.

_root.spaceShip._x=350;

_xscale
This property returns the x scale of an object. In the example shown here
the x scale of a movie clip instance named spaceShip is being changed to
50 percent.

_root.spaceShip._xscale=50;
1637-X BC02.F 5/9/02 3:12 PM Page CD-13

Bonus Chapter 2: ActionScript Properties Dictionary CD-13

_xmouse
Returns the x position of the mouse. This property is useful for determining
where a players cursor is during a game. In the following example a variable
named xposition is set equal to the x position of the users cursor.

xposition = _xmouse;

_y
This property returns the y position of an object. In the example shown here
the y coordinate of the movie clip instance spaceShip is being set to 200.

_root.spaceShip._y=200;

_yscale
This property returns the y scale of an object. In the following example the x
scale of a movie clip instance named spaceShip is being changed to 20 percent.

_root.spaceShip._yscale=20;

_ymouse
This property returns the y position of the mouse. This property is useful for
determining where a players cursor is during a game. In the example shown
here a variable named yposition is set equal to the y position of the users
cursor.

yposition = _ymouse;
1637-X BC02.F 5/9/02 3:12 PM Page CD-14

CD-14 Macromedia Flash ActionScript MX For Dummies


1637-X BC03.F 5/9/02 3:12 PM Page CD-15

Bonus Chapter 3

ActionScript Objects Dictionary


F lash has a lot of objects for you to work with more objects, in fact,
than youll probably ever need unless youre a programmer. In this
appendix, I cover what I feel are the most popular and useful objects. In order
for objects to work their magic, each object has methods that are used to
retrieve or store information. Some of the objects have a great number of
methods. For each of the following objects, I list what I feel are the most
popular and useful methods, plus I show you examples of how to use them.

Yikes, some of these object books are buried in other object books! Not to
worry, I give you a roadmap to the object book at the start of each section.
When you see ObjectsMovieColor, you click the book icons in that order,
and youre there.

Array
To get to this object book the path is ObjectsCoreArray. Sometimes you
have to go one step further and click the Methods book icon. Whenever you
see a following section listed as an object method, click the Methods book
icon after you get in the Array book. If one of the following sections is listed
as a property, after arriving in arraysville, click the Properties book icon.
Whew, thats a lot of books.

Arrays are your basic variables on steroids. Theyre powerful; you can pack
tons of data in an array. You use the Array object to create a variable that
stores similar data. For example, an array would be the ideal vehicle to store
the names of a companys employees. After you create an Array object, you
use the Array objects methods to manipulate the data. Listed next are the
most commonly used Array methods.
1637-X BC03.F 5/9/02 3:12 PM Page CD-16

CD-16 Macromedia Flash ActionScript MX For Dummies

For more information on arrays, sneak a peek at Chapter 6.

new Array
This action creates a new Array object. In the following example, a new array
called username is created and filled with the elements between the parenthe-
ses. If the array is string literal data, each element must be surrounded with
quotation marks. You use a comma to separate individual elements in the
array.

username = new Array(Patti, Susan, Boyd, Woody,


Nash);

concat
This method of the Array object concatenates the elements of the specified
arrays and then creates and returns a new array. In the example shown here,
the last line of code would create a new array called databank. The elements
of databank are [Patti, Susan, Boyd, Woody, Nash, 256,
Awesome, Numero Uno, Yes, Wild One].

username = new Array(Patti, Susan, Boyd, Woody, Nash);


password = new Array(256, Awesome, Numero Uno, Yes,
Wild One);
databank=username.concat(password)

length
This property returns the number of elements in an array. This information
is useful, for example, when you need to know the number of elements in an
array to process other data. You could just count the number of elements
in the array and use that number. However if you change the number of
elements in the array, you need to remember to change that number in
any expressions where you used it. Using the length method automatically
updates the number when you add or delete elements from the array. The
following example shows a variable named members that is set equal to
the number of elements in an array called users.

members = users.length;
1637-X BC03.F 5/9/02 3:12 PM Page CD-17

Bonus Chapter 3: ActionScript Objects Dictionary CD-17

reverse
This method reverses the order of an array. In the example shown here, the
second line of code would reorder the array to: Nash, Woody, Boyd, Susan, Patti.

username = new Array(Patti, Susan, Boyd, Woody, Nash);


username.reverse;

sort
This method sorts the elements in an array. In the following example, the
second line of code would sort the array to: Boyd, Nash, Patti, Susan, Woody.

username = new Array(Patti, Susan, Boyd, Woody, Nash);


username.sort;

Color
Your path to color is a good television set . . . er, actually in the Actions panel,
the path is ObjectsMovieColor, and sometimes you have to open the
Methods book when you see a listing that says it is a method of the color
object. You use the Color object to set and retrieve the color of movie clip
objects. The first step is creating a Color object and then using one of the
methods to alter the color.

new Color
This is the actual Color object. Before you can transform a movie clips
colors, you must first create a Color object as shown here. The item in
parentheses is the target movie clip that the Color object will modify.

mycolor = new Color(color_clip);

setRGB
You use this method of the Color object to transform a color. The format
used is the hexadecimal color set. The following example shows the method
being used to transform a movie clip bright red.

mycolor.setRGB( 0xFF3333);
1637-X BC03.F 5/9/02 3:12 PM Page CD-18

CD-18 Macromedia Flash ActionScript MX For Dummies

setTransform
You use this method of the Color object to tint a bitmap image. To use this
method, you need to create a generic object as shown in the first line of code
in the following example. The second line of code specifies the color trans-
formation, and the third line of code applies the transformation to the Color
object using the generic object created in the first line of code.

myColorTransform = new Object();


myColorTransform = {ra:56, rb:225, ga:75, gb:-200,
ba:100, bb:145, aa:75, ab:100};
myColor.setTransform(myColorTransform);

For more information on the Color object, refer to Chapter 8.

Date
The Date book is another one of those books thats buried deep in the
Actions panel. But you can get there from here by following this path in
the Actions panel: ObjectsCoreDate and Method when you see a section
listed as a method of the Date object.

You use the Date object to create a match-making program for single adults.
Kidding. Actually you use the various methods of the Date object to retrieve
the current date and time from the host computers (the computer playing
the Flash movie) operating system. Listed next are the most commonly used
methods of the Date object and examples of them in action.

new Date
This is the actual Date object itself. Before you can retrieve the date or time
from the computers operating system, you must first create a Date object as
shown here.

mydate = new Date();

getDate
This method of the Date object returns the current date. The following exam-
ple shows the method being used to pass the current date to a variable called
date.

date = mydate.getDate();
1637-X BC03.F 5/9/02 3:12 PM Page CD-19

Bonus Chapter 3: ActionScript Objects Dictionary CD-19

getDay
This method of the Date object returns the current day. In the following exam-
ple, a variable called day will return the current day using the getDay method.

day = mydate.getDay();

getMonth
This method of the Date object returns the current month. In the example
shown here, the value of a variable named month is set equal to the current
month as retrieved by the getMonth method of the Date object. Flash starts
counting the months at 0. In order to show the proper month in numeric
form, you must create an expression that adds one to the value the getMonth
method returns.

month = mydate.getMonth();

getFullYear
This method of the Date object returns the full year. In the following example,
a variable named year has its value set equal to the current year using this
method.

year = mydate.getFullYear();

getHour
This method of the Date object returns the current hour from the host com-
puters clock, which is based on the 24-hour clock. Unless youre creating
a movie for the military, you will have to convert the time to the standard
12-hour clock. In the example shown here, the variable hours is set equal
to the current hour using this method.

hours = mydate.getHours();

getMinutes
This method of the Date object returns the current minute from the host
computers clock. In the following example, the variable minutes is set
equal to the current minute, which is retrieved using this method.

minutes = mydate.getMinutes();
1637-X BC03.F 5/9/02 3:12 PM Page CD-20

CD-20 Macromedia Flash ActionScript MX For Dummies

getSeconds
This method of the Date object shows the current second based on the host
computers clock. In the example shown here a variable named seconds is
set equal to the current second, which is retrieved using this method.

seconds = mydate.getSeconds();

For more information on the Date object, refer to Chapter 8.

Math
The path to the methods in this section is ObjectsMathMethods.
When you get there, you see that there really is a numerical method to
this madness.

The Math object has a whole lot of methods. If youre into Algebra and other
tricky math that requires a slide rule or turbo-charged abacus and want to
include them in your Flash movies, by all means explore the other methods.
Next I show you the two methods I feel are the most useful.

random
This method of the Math object returns a random number between 0 and 1.
You can multiply the random number generated by any other number to
create a higher random number. In the following example, the variable
guessNumber will be between 1 and 64.

guessNumber = Math.random ()*64;

round
This method of the Math object will round a number to the next nearest
integer. In the example shown here, the method is being used to round off
a random number between 1 and 50.

guessNumber = Math.round (Math.random ()*50);


1637-X BC03.F 5/9/02 3:12 PM Page CD-21

Bonus Chapter 3: ActionScript Objects Dictionary CD-21

Mouse
A mouse is an object that can only be loved by another mouse or a com-
puter user with a steady right (or left for you lefties) hand. The path to the
mouse object is not littered with cheese crumbs; rather it is Objects
MovieMouseMethods.

You use the Mouse object when you want to hide or show the cursor in a
Flash movie. The object has only two methods, Hide, and Show.

hide
This method of the Mouse object hides the mouse. Now you see it, now you
dont.

Mouse.hide();

show
This method of the Mouse object reveals a cursor previously hidden using
the hide method.

Mouse.hide();

Sound
The Sound object can be seen in the Actions panel and heard in your pub-
lished movies. But before you can hear the Sound object, youve got to
follow this long and winding road: ObjectsMoviesSounds and some-
times Method when a section item is listed as a method of the sound
object.

You use the Sound object to modify a sound in your movie. In order to use
the objects methods, you must first create a Sound object, and then attach a
sound to the object. Listed here are the most popular methods of the Sound
object.
1637-X BC03.F 5/9/02 3:12 PM Page CD-22

CD-22 Macromedia Flash ActionScript MX For Dummies

new Sound
This creates the actual Sound object. The following example shows how to
create the object.

soundtrack = new Sound();

attach Sound
This method of the Sound object attaches the sound you are going to modify.
The proper syntax is shown in the example shown here where a soundtrack
movie loaded into level 1 is attached to the sound. You could also attach a
movie clip with a sound embedded in it. In that case, you would insert the
target path to the movie clip between the parentheses.

soundtrack.attachSound(_level1);

setPan
You use this Sound object method to adjust the balance between the two
speakers. The range is 100 (plays only in the left speaker) to 100 (plays in
the right speaker). The following example will bias most of the sound toward
the left speaker.

soundtrack.setPan(-50);

setVolume
You use this Sound object method to control the volume of a sound. The
range is 0 (no sound) to 100 (full volume). You can specify a range higher
than 100, but the sound will be distorted. In the example shown here, the
sound will play at 75 percent volume.

soundtrack.setVolume(75);

start
You use this method to begin playing a Sound object.

soundtrack.start ()
1637-X BC03.F 5/9/02 3:12 PM Page CD-23

Bonus Chapter 3: ActionScript Objects Dictionary CD-23

stop
You use this method of the Sound object to stop a sound object from playing.

soundtrack.stop()

For more information on the Sound object and its methods, refer to Chapter 8.
1637-X BC03.F 5/9/02 3:12 PM Page CD-24

CD-24 Macromedia Flash ActionScript MX For Dummies


1637-X BC04.F 5/9/02 3:12 PM Page CD-25

Bonus Chapter 4

Ten Showcase Web Sites


to Inspire You
E verybody needs some inspiration sometime. When youre having a bad
day and the creative juices are flowing like molasses uphill, sometimes
you need a little jumpstart to get your creative juices flowing. I always find a
trip to the Internet and a good strong cup of coffee are the best antidotes for
a case of Flash block. In this chapter, I show you some sites that are excellent
examples of Flash movies that use ActionScript and other cool techniques to
good effect. And yeah, my abacus short-circuited on this chapter, too you
actually get 11 Web sites.

Macromedia Showcase
The Macromedia Showcase (www.macromedia.com/showcase) is where you
find the crme-de-la-crme of Flash movies. Every day with the exception
of weekends when the Flash techno-geeks take a brief respite and do really
cool things like surf the net youll find a new Web site featured in the
Macromedia Showcase. The sites are varied. When my schedule permits,
I check them out to see the latest and greatest innovations in Web design.
Most of the Web sites featured are Flash based because theyre almost always
the coolest.

Pink Floyd
If youre too young to remember who Pink Floyd is, or why he is pink, youll
still appreciate this well-done Flash site. Go to www.pinkfloyd.co.uk to
learn about the groups latest release, which is actually a re-release of some
of their popular tunes. Check out the navigation menu of record album
covers (you know, those colorful cardboard things that used to cover records
before CDs became all the rage). Click an album cover to learn more about
the featured song from that album.
1637-X BC04.F 5/9/02 3:12 PM Page CD-26

CD-26 Macromedia Flash ActionScript MX For Dummies

Sheer Blond
If youre a guy Flash ActionScript specialist, youll love the models (two
lovely young ladies named Alex and Brit) at this site. If youre a gal Flash
ActionScript guru and a blonde (gotta love em theyre the most attractive
and brilliant people on the planet), youll appreciate the products promoted
at this site. Its got some very cool Flash work. Point your Web browser to
www.johnfrieda.com/flash.htm and enjoy.

Jacobs Creek
This Australian wine producers Jacobs Creek Web site (www.jacobscreek.
com.au) features excellent use of vector-based graphics along with a very
nice intro. Check out the preloader, which is a bottle of wine filling up and
then being labeled. The site features a unique navigation menu with movie
clips that play when a navigation button is rolled over (in the case of this
Flash movie, each button is a text object). Each section of the site appears to
be a separate movie, loaded with the Load Movie action. Although each indi-
vidual section is large, the sites designer created them in such a manner to
stream into the browser without interruption, thereby eliminating the need
for a preloader.

Pickled the Movie


This branch of Billabongs site (www.billabong-usa.com) features some
very jittery buttons that come to life when you roll your mouse over them.
In addition to the cool buttons, the site demonstrates how to mix vector
graphics with bitmaps for maximum effect. Go there. Youll like it.

George Michael
Heres a cool music Web site. Even if youre not a George Michael fan, youll
enjoy the graphics and the menu is done well. There are also some cool
scrolling text boxes and a control panel that you can use to load background
music or change the background image. Point your Web browser to: www.
Georgemichael.com and get ready for a treat.
1637-X BC04.F 5/9/02 3:12 PM Page CD-27

Bonus Chapter 4: Ten Showcase Web Sites to Inspire You CD-27

Team Audio
The Team Audio site (www.teamaudio.com) features yet another twist on
the gateway page. You have the choice of two Flash movies, one created for
modem connection and the other for cable or DSL connection. Unfortunately,
I was not able to test the high bandwidth site as my current ISP is modem-
based. However, the modem site is quite interesting. It features a nice naviga-
tion menu that uses sound. When you roll your mouse over a button, you get
an audio message; which should come as no surprise as this is a site special-
izing in audio.

Rob Allen Photography


If you like things that move but stop when you put your mouse over
them, check out the moving menu at the Rob Allen Photography site (www.
roballen.ca). The site is artfully done in black and white (okay, grayscale
for you image-editing nerds) and features a way-cool moving navigation
menu. Move your mouse over the menu, and it stops quicker than a Ferrari
with four-wheel disc brakes.

Juxt Interactive
Juxt Interactive (www.juxtinteractive.com) creates high-intensity Flash
sites that are the epitome of good taste. When you launch its Web site, you
reach a gateway with entryways to its Flash and HTML sites. Although both
are quite intriguing, I suggest you explore the Flash site, which is a showcase
of everything thats wonderful about Flash. The text used in the site is espe-
cially artistic and creative. In this site youll find an interesting mix of motion,
sound, and artistic color. The portfolio section features a drag-and-drop inter-
face. Click one of the buttons and drag it into the folder to launch a movie
that showcases a site or project created by this talented design team.

Pepworks.com
The browser title for Pepworks.com (www.pepworks.com) reads as follows:
(pepworks interactive entertainment) design, games, and fun. I couldnt put it
any better. The site features a great introduction. After the intro plays and the
interface loads, click the 2002 version of Leos Great Day button for an excel-
lent example of an interactive Flash game. Enjoy.
1637-X BC04.F 5/9/02 3:12 PM Page CD-28

CD-28 Macromedia Flash ActionScript MX For Dummies

n.fuse.gfx
With the influx of faster cable connections, n.fuse.gfx (www.nfusegfx.com)
is yet another site that gives you the choice between a low-bandwidth Flash
presentation (modem only) and a high-bandwidth Flash site (DSL or cable
connection). I was only able to sample the low-bandwidth Flash site that
starts out with a very unique intro. After viewing the intro, you get a slick
interface to work with and some excellent background music. The low-
bandwidth site features excellent use of sound, vector graphics, and unique
rollover buttons. I suspect theres quite a bit of ActionScript lurking under
the hood of this sites Flash engine.
1637-X BC05.F 5/9/02 3:12 PM Page CD-29

Bonus Chapter 5

Creating Printable Movie Frames


I f youre creating a Flash movie for an e-commerce site, you can create
printable movie frames. When you create printable movie frames, viewers
of the Flash movie can print a copy of the frame on their computer printers,
which is a wonderful way to get a spec sheet in a potential customers hands.
You can specify the print area that you want and then program a button to
print the area when clicked. In the upcoming exercise, I show you how to
create a printable frame. The object of the printable frame is near and dear to
my heart; its the cover of my fourth book, Fireworks 4 For Dummies (pub-
lished by Hungry Minds, Inc.).

To follow along with this exercise, copy the file named printable_frame_
begin.fla (conveniently located in a folder called printable_frames folder in
this chapters folder on the CD that accompanies this book) to your hard
drive. Use your computers operating system to disable the files Read Only
attributes.

1. Launch Flash and open the File printable_frame_begin.fla.


Flash opens the file. The movie is a small one; a single frame with a copy
of my fourth books cover for your viewing pleasure and some descrip-
tive text. Theres also a button that youll program to print the book
cover and text on demand.
2. Click the first frame.
3. Click the triangle to the left of the word Properties.
The Property inspector opens.
4. In the <Frame Label> field, type #p.
This label tells Flash that the frame is printable. Now youve got to spec-
ify the area you want printed. You can have Flash print the whole page,
but that includes the button, which is something your viewer has no
interest in. Leave the Property inspector open; youll be using it again
shortly.
5. Click the second frame and then choose InsertBlank Keyframe.
Flash creates a blank keyframe.
1637-X BC05.F 5/9/02 3:12 PM Page CD-30

CD-30 Macromedia Flash ActionScript MX For Dummies

6. In the Property inspector, type #b in the <Frame Label> field.


This label tells Flash that the contents of this frame act as a bounding
box or printable area. Now all youve got to do is create the bounding
box.
7. Click the Onion Skin button, which is the second button youll find
below the timeline.
You now see an onion skin outline of the book cover, text, and the
button.
8. Select the Rectangle tool and then draw a rectangle with no fill that
surrounds the book cover and text (see the following figure).
If you dont get the rectangle perfectly centered, use the Align panel
to horizontally center it to Stage.

9. Click the Onion Skin button.


Flash disables onion skin viewing.
10. Click the first frame, and in the left pane of the Actions panel, click
ActionsMovie Control and then double-click stop.
Flash adds a stop action to the frame. Without it the movie would jump
back and forth between the two frames.
1637-X BC05.F 5/9/02 3:12 PM Page CD-31

Bonus Chapter 5: Creating Printable Movie Frames CD-31


11. Click the button on Stage and then click the arrow to the left of the
word Actions.
The Actions panel opens.
12. Click Printing and then double-click Print.
The Print action is added to the script, and the Print actions parameters
appear above the Script pane.
13. For this exercise, accept the default parameters.
When you create your own printable frames, you may have to change
the parameters to suit the frame youre printing.
Here are the available parameters you can modify when you print your
own frames:
Print: You have two options, As vectors and As bitmaps.
Choose As vectors to create a higher quality printed image but
without transparency. Choose As bitmaps to create a print that
shows any color or alpha effects you applied to objects in the
frame.
Location: This parameter refers to the location of the frame you
want printed when the button is clicked. If the printable frame is
on the main timeline, accept the default level0; otherwise, specify
the level the printable frame is on. If the printable frame is in a
movie clip, choose Target and then use the Insert a Target Path
button to specify the path to the movie clip the printable frame
is in.
Bounding Box: This option refers to the area of the frame that will
be printed. Choose the default Movie option and Flash uses the
bounding box of the object you create in the frame labeled #b.
Choose Max and Flash uses the largest printable frame bounding
box for the print area. Choose Frame if you want Flash to use the
bounding box or all objects in each printable frame. If you have
different-sized objects in each frame, Flash scales the objects to
match the print area.
14. Choose ControlTest Movie.
Flash publishes the movie and plays it in another window.
15. Click the Print button.
The dialog box for your computers default printer opens, enabling you
to print a copy of my book cover.
1637-X BC05.F 5/9/02 3:12 PM Page CD-32

CD-32 Macromedia Flash ActionScript MX For Dummies


1637-X BC06.F 5/9/02 3:12 PM Page CD-33

Bonus Chapter 6

Creating a Visitor Response Form


I f youve ever created an e-commerce site using standard HTML, chances
are youve created some type of visitor response or feedback form. You
can also create a form with Flash and have the response forwarded to your
clients e-mail. To create a response form with Flash, you use Input text to
get the information from the visitor and then transmit the variables to the
site servers forwarding program using the getURL action. Heres how.

To follow along with this exercise copy the file named response_form_
begin.fla from this chapters folder on the CD to your hard drive. Use
your operating system to disable the files Read Only attributes.

1. Launch Flash and open the response_form.fla file.


Flash opens the file, which is a movie in which Ive already set up the
form for you. Its a typical response form you find on many Web sites,
complete with fields for the viewers to give their contact information
and submit any comments or queries. Each one of the fields is an input
text box but you probably already knew that, didnt you? Each text
box has a variable assigned to it. The contents of each variable are what
will be submitted to the site servers mail forwarding program for pro-
cessing and eventually sent to the specified recipient in the form of an
e-mail.
2. Click the Submit button.
3. Click the arrow to the left of the word Actions.
The Actions panel appears.
4. In the left pane of the Actions panel, click ActionsBrowser/Network
and then double-click getURL.
The action is added to the script, and three fields open in the
Parameters pane.
5. In the URL field, enter the path to the sites mail forwarding script.
Listing 1 shows an example of a typical path to a servers forwarding
script.
1637-X BC06.F 5/9/02 3:12 PM Page CD-34

CD-34 Macromedia Flash ActionScript MX For Dummies

Listing 1 Forwarding to a CGI Script


http://www.yourcompany.com/cgi-bin/formmail.pl

6. Click the triangle to the right of the Variables field and choose Send
Using Get from the drop-down menu.
After the movie is published, Flash sends the variables from the form to
the server using the GET method. In other words, Flash gets the info
from the variables in the movie.
Most mail forwarding scripts need a variable called recipient transmit-
ted with the data in order to work properly. The recipient is the e-mail
address that the variables are forwarded to.
7. Click the first frame in the Actions layer.
8. In the left pane of the Actions panel, click ActionsVariables and then
double-click set variable.
Two fields open up above the Script pane.
9. In the Variable field, type recipient and in the Value field, enter the
e-mail address of the party that will receive the forms results.
Most mail scripts will not function without a value for recipient. Check
with the site servers technical support staff to see what information is
required for its forwarding script.
10. Click the Reset button.
The Actions panel should read Actions-Button. If it doesnt, you havent
properly selected the button; click it again, Sam.
11. In the left pane of the Actions panel, click ActionsVariables and then
double-click set variable.
Once again the parameters text boxes appear with nothing in them.
12. In the Variable field, type name and leave the Value field empty.
The purpose of this line of code is to reset the value of each variable
to null, or empty, when the Reset button is clicked.
13. Repeat Step 12 for the remaining variables in the form: address, city,
state, zip, phone, e-mail, and comments.
When the Reset button is clicked, the content of each variable empties.
This gives the viewer a chance to resubmit the information if he or she
had a typo. It also gives someone else viewing the same movie at the
same time a chance to submit his or her information.
14. If you were creating this form for an actual Web site, you could give
the form a trial run by choosing FilePublish Preview.
When you choose the Publish Preview command, Flash publishes the
movie so you can preview it in a browser. If you preview the movie while
1637-X BC06.F 5/9/02 3:12 PM Page CD-35

Bonus Chapter 6: Creating a Visitor Response Form CD-35


logged on to the Internet, you can fill out the form and then click the
Submit button to make sure the results are forwarded to the specified
recipient.

Many Web servers use a script called mailto.exe instead of a CGI script to for-
ward form results. If this is the case with your sites server, they will furnish
instructions on how to set up an HTML document for the script and transmit
the information using the POST method. Listing 2 shows an example of HTML
code for a mail forwarding script.

Listing 2 HTML for Mail Forwarding


<form action=http://scripts.myserver.com/cgi-bin/mailto.exe
method=POST onSubmit=return
FrontPage_Form1_Validator(this)
name=FrontPage_Form1>
<input type=hidden name=sendto
value=webmastersdesigns.net>
<input type=hidden name=server
value=smtp.myserver.com>
<input type=hidden name=subject value=Form Processed
Email Response>
<input type=hidden name=resulturl
value=http://www.dasdesigns.net/thanks.htm>
<input type=hidden name=VTI-GROUP value=0>

The preceding HTML code is for the mail forwarding script used by my Web
sites host. There is certain information in the form that must be present in
order for the form to work properly and forward the information to the recip-
ient, who in the above case happens to be the author of this book. When you
get right down to it, the required information are variables. To make this
script work properly with the Flash form you just programmed:

1. In Step 5 of the previous numbered list, type the following path in the
URL field: http://scripts.myserver.com/cgi-bin/mailto.exe
This is the path to the where the server keeps all of the scripts. Check
with your sites hosting server for the actual path or copy the path from
the servers instructions and paste it into the field. Notice that this is the
same path listed in the form action HTML tag in Listing 2.
2. Click the triangle to the right of the Variable field and choose Send
using GET.
3. Click the first frame in the Actions layer and declare the following
variables using the set variable action:
sendto = webmastersdesigns.net;
server = smtp.myserver.com;
1637-X BC06.F 5/9/02 3:12 PM Page CD-36

CD-36 Macromedia Flash ActionScript MX For Dummies

subject = Form Processed Email Response;


resulturl = http://www.dasdesigns.net/thanks.htm;
Compare the preceding variables to the each line of code with the input
type tag in Listing 2. After a bit of experimentation, I determined that the
first four name items and their values were needed to properly execute
my servers script. Notice that each name from the HTML code becomes
a variable in the Flash movie, and the names value becomes the vari-
ables value in the ActionScript. The actual variables you use depend
upon the script your server provides. You may have to experiment a bit
to find which ones are needed for your servers particular forwarding
script. It shouldnt take you more than a minute or two to figure out
which ones are needed for your movie.
The following figure shows an example of a mail forwarding script
transformed into variables in an ActionScript. The variables are sent to
the server when the form is submitted and if the variables are correct, the
results of the form are forwarded to the proper recipient. If you get the
variables wrong, its almost like sending out mail with a bad zip code
you never know where it might end up.
1637-X BC06.F 5/9/02 3:12 PM Page CD-37

Bonus Chapter 6: Creating a Visitor Response Form CD-37


To see an example of this response form with forwarding to an actual e-mail
address, launch and open the response_form_final.fla file located in this chap-
ters folder on the CD. Click the first frame in the movies Actions layer to see
the variables that will be sent to the sites server. Click the Submit and Reset
button to examine the code used to send the variables and reset the form.

If the site youre creating a Flash form for doesnt have a mail forwarding
form, you can get one for free at www.worldwidemart.com/scripts/
formmail.shtml. After you download the form, follow the instructions
included in the Readme file to set up the form. Contact the sites host for
instructions on which directory you should upload the form to. In most
cases, it will be directory named cgi-bin.
1637-X BC06.F 5/9/02 3:12 PM Page CD-38

CD-38 Macromedia Flash ActionScript MX For Dummies

Potrebbero piacerti anche