ActionScripting in Flash 1st Edition Phillip Kerman instant download
ActionScripting in Flash 1st Edition Phillip Kerman instant download
https://ebookfinal.com/download/actionscripting-in-flash-1st-
edition-phillip-kerman/
https://ebookfinal.com/download/flash-floods-in-texas-1st-ed-edition-
burnett/
https://ebookfinal.com/download/chemical-bonds-1st-edition-phillip-
manning/
https://ebookfinal.com/download/hands-on-guide-to-flash-video-web-
video-and-flash-media-server-1st-edition-stefan-richter/
Flash MX Studio 1st Edition Dennis Baldwin
https://ebookfinal.com/download/flash-mx-studio-1st-edition-dennis-
baldwin/
https://ebookfinal.com/download/pro-android-flash-1st-edition-stephen-
chin/
https://ebookfinal.com/download/ophthalmic-disease-in-veterinary-
medicine-2n-edition-phillip-a-moore/
https://ebookfinal.com/download/psychophysical-acting-1st-edition-
phillip-b-zarrilli/
https://ebookfinal.com/download/america-s-role-in-the-world-global-
issues-1st-edition-phillip-margulies/
ActionScripting in Flash 1st Edition Phillip Kerman
Digital Instant Download
Author(s): Phillip Kerman
ISBN(s): 9780672320781, 0672320789
Edition: 1st
File Details: PDF, 4.76 MB
Year: 2001
Language: english
00 0789 FM 3/20/01 3:51 PM Page i
Phillip Kerman
{ ActionScripting
in FLASH }
™
All terms mentioned in this book that are known to be trade- Interior Designer
marks or service marks have been appropriately capitalized. Alan Clements
Sams Publishing cannot attest to the accuracy of this informa- Cover Designer
tion. Use of a term in this book should not be regarded as affect- Alan Clements
ing the validity of any trademark or service mark.
Page Layout
Ayanna Lacey
Warning and Disclaimer Heather Hiatt Miller
Stacey Richwine
Every effort has been made to make this book as complete and
DeRome
as accurate as possible, but no warranty or fitness is implied.
The information provided is on an “as is” basis. The author and
the publisher shall have neither liability nor responsibility to any
person or entity with respect to any loss or damages arising from
the information contained in this book.
00 0789 FM 3/20/01 3:51 PM Page iii
Overview
Part I Foundation 1
{ Foundation } Introduction 3
1 Flash Basics 7
2 What’s New in Flash 5 25
3 The Programmer’s Approach 37
4 Basic Programming in Flash 47
5 Programming Structures 73
6 Debugging 113
7 The Movie Clip Object 141
8 Functions 161
9 Selecting Text, Trapping Keys, and Manipulating Strings 185
10 Arrays 211
11 Objects 237
12 Homemade Objects 261
13 Smart Clips 283
14 Interfacing with External Data 303
Contents
Part I Foundation 1
{ Foundation } Introduction 3
1 Flash Basics 7
Timeline Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Implications for Animation and Filesize . . . . . . . . . . . . . . . . . . . 8
Implications for Programming . . . . . . . . . . . . . . . . . . . . . . . . . 10
Targeting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Script Locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Always Movie Clips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Coordinate System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Tricks of the Trade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Invisible Buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Empty Movie Clips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Empty Layers and Keyframes. . . . . . . . . . . . . . . . . . . . . . . . . . 23
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
vi ActionScripting in Flash
5 Programming Structures 73
Statements, Expressions, and Operators. . . . . . . . . . . . . . . . . . . . . 73
Writing Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Using Operators in Expressions . . . . . . . . . . . . . . . . . . . . . . . . 77
Types of Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Built-in Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Simple Objects in Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Using the Math Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Using the Number Object. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Conditional and Loop Statements . . . . . . . . . . . . . . . . . . . . . . . . . 96
Conditional Statements: if, if else, if else if . . . . . . . . . . 97
Loop Statements: for, for in . . . . . . . . . . . . . . . . . . . . . . . . 101
while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Applied Expression Writing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
6 Debugging 113
General Approaches to a Bug-Free Life. . . . . . . . . . . . . . . . . . . . 114
Finding and Defining Bugs. . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Fixing Bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Preventing Bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Using the Debugger. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Viewing and Setting Properties and Variables . . . . . . . . . . . . . 122
Watching Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
00 0789 FM 3/20/01 3:51 PM Page vii
Contents vii
8 Functions 161
How to Use Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Using Built-in Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Using Homemade Functions. . . . . . . . . . . . . . . . . . . . . . . . . . 164
Creating Homemade Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Functions as Subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Making Functions That Accept Parameters . . . . . . . . . . . . . . . 170
Making Functions That Return Values . . . . . . . . . . . . . . . . . . 173
Using Functions as Methods. . . . . . . . . . . . . . . . . . . . . . . . . . 175
Local Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Applying Functions to Previous Knowledge . . . . . . . . . . . . . . . . 179
Review Built-in Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Things to Remember . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
10 Arrays 211
Array Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Array Creation and Manipulation . . . . . . . . . . . . . . . . . . . . . . . . 215
Creating and Populating Arrays . . . . . . . . . . . . . . . . . . . . . . . 215
Accessing Array Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Array Object Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Associative Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
11 Objects 237
Formal Rules of Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Attach Sound. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Sound Object Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Advanced Sound Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Controlling Multiple Sounds . . . . . . . . . . . . . . . . . . . . . . . . . 243
Color. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Simple Coloring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Using RGB Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Using the Color Transform Method . . . . . . . . . . . . . . . . . . . . 248
Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Instantiating a Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Manipulating Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Attach Movie Clip. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Contents ix
6 Mapping 413
x ActionScripting in Flash
Contents xi
Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
Hint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570
Move Multiple. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570
Hint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571
Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571
Index 589
00 0789 FM 3/20/01 3:51 PM Page xii
Foreword
This book targets the reader who can assemble a basic Flash movie and who
knows what he or she wants to achieve. I’ll help you divide your goal into indi-
vidual tasks that can then be translated into ActionScript. Naturally, this will
involve teaching you how to “program” (and even think like a programmer). This
book is not, however, a general programming book; every topic is related to and
applied to Flash. Naturally, if you are already an experienced programmer, you
might find parts of this book to be a review. But for you programmers, I’ll show
you how to apply your programming knowledge to make Flash perform. All the
programming skill in the world (whether I teach it to you or you bring it with
you) won’t help you if you can’t apply it to Flash.
This book definitely does not shy away from advanced topics. But it isn’t an
exhaustive reference to every detail in the ActionScript language either. The truth
is that there are countless other resources for advanced programming topics.
That’s not what this book is about. It’s about giving you the skills so that you can
apply any idea you have to Flash. When you’re equipped with the knowledge I
cover, you’ll be able to meet any challenge. It might involve researching an eso-
teric formula for physics or applying a unique math calculation. If that means
you have to research a specific topic, this book will give you the skills to figure
out how to apply it to Flash.
I started this book having just finished Sams Teach Yourself Macromedia Flash 5
in 24 Hours. Although this isn’t a continuation of that book, there isn’t much
repeated content either. I said earlier that you’ll need to be able to assemble a
Flash movie (for example, I’m not going to teach you how to draw in Flash). The
first chapter, “Flash Basics,” goes over the prerequisites. It’s important that you
come with this basic knowledge. Don’t worry, I won’t go so fast that you can’t
keep up, but everyone should start at this base level.
00 0789 FM 3/20/01 3:51 PM Page xiii
Contents xiii
The book is organized in two parts. The foundation chapters are like a textbook.
Plenty of examples are interspersed, but you won’t need to follow along with
Flash running. (I suspect, however, that you’ll often want to try things out when
inspired.) The workshop chapters are all hands-on tutorials. It’s a chance to apply
what you learned in the foundation part. If you prefer, you can jump right into
the workshops as references are made to the foundations when further explana-
tion might be helpful. You’ll find the workshops to be quite useful. In some of
them, I even guide you down the wrong path so that we can discuss the solution
that follows. I find that this is more true-to-life than some tutorials that seem to
prove only that it’s possible to achieve a particular result with very few steps.
Real life is often frustrating and perhaps the simulated reality of these workshops
will help you avoid frustration when you go on your own.
One last note before we get rolling. Flash 5 was such a change from Flash 4 that
I chose to cover only Flash 5. It turns out that there are a few ancillary mentions
of Flash 4 in this book, including a good part of Appendix A, “Equivalents.” By
and large, however, this book is for Flash 5 only. The first workshop provides
information about ensuring that your users have the correct Flash player.
Naturally, you’ll be shown how to upgrade those users so that they can see your
Flash 5 creations.
Phillip has transitioned his expertise from Authorware to Director, and now, to
Flash. Over seven years, he has had to adapt to a total of 13 version upgrades—
Flash 5 being the most significant of them all! In addition to retooling and build-
ing his own skills, Phillip finds teaching the biggest challenge. He has trained
and made presentations around the world, in such exotic locations as Reykjavik,
Iceland; Melbourne, Australia; Amsterdam, Holland; and McAlester, Oklahoma.
He wrote Sams Teach Yourself Macromedia Flash 5 in 24 Hours (that is the title,
not how long it took to write). His writing has also appeared in such publications
as Macworld, Macromedia User Journal, and his self-published The Phillip
Newsletter (www.teleport.com/~phillip/newsletter).
In addition to showing others how to create multimedia, Phillip has had plenty of
opportunities to get his hands dirty in programming. Last century, Phillip pro-
grammed the all-Flash Web site www.m-three.com for Paris France Inc. This site
was included in both Communication Arts Interactive Design Annual and the
British Design & Art Direction Annual in 2000. The latest version of the M3 site
won the navigation category at the London Flash Film Festival.
Contents xv
Dedication
Acknowledgments
The hardest part of writing a book is attempting to acknowledge all those who
helped, but knowing that you’ll fail to mention everyone. Here is my attempt to
acknowledge everyone.
First, the people at Sams Publishing. You’ll find a list of the key players in the
credits column on the copyright page, but even they would acknowledge that oth-
ers helped them. After seeing my first book become a reality last year (with the
same team), I realized that even if I could write a perfect book on my own
(which, of course I can’t), it would never get printed because there’s so much
work involved in preparing the files for the printer. Although I can’t say I know
how every publisher works, I can say that Sams is professional, responsive, and
fun. Of particular note, Kate Small made the book flow. Everything seemed to
make sense when I wrote it, but after Kate reorganized parts, it made much more
sense. Lynn Baus used her Flash experience both to ensure that technical details
were correct and exercises could be performed, as well as to suggest countless
additional facts that were included in the text. Copy editors are doubly valuable
as they both eliminate errors that would otherwise make the book difficult to read
and they also make me a better writer! Reviewing their edits is like a free
English class. The production team led by Carol Bowers turns the manuscripts
into a real book. Obviously, there are many others who work behind the scenes
for whom I am grateful.
Santangeli, and Eric J. Wittman. Others who provided specific help for this book
include Jeremy Clark and Matt Wobensmith.
I subscribe to many e-mail lists, but four in particular have been most helpful—
those run by Darrel Plant, Branden Hall, Jon Warren Lentz, and Robert
Reinhardt. There are countless instances when a thread on one of these lists has
helped me.
One last acknowledgment for some authors of other Flash books. I’m proud of
this book, but it contains only my style of communication. For some different
perspectives on Flash, check out books containing contributions by the following
authors:
I can’t vouch for books I haven’t reviewed, but I can say these folks know their
stuff. They’ve also provided direct help on various Flash related matters to
myself and others for years.
00 0789 FM 3/20/01 3:51 PM Page xvii
Contents xvii
As the reader of this book, you are our most important critic and commentator.
We value your opinion and want to know what we’re doing right, what we could
do better, what areas you’d like to see us publish in, and any other words of wis-
dom you’re willing to pass our way.
You can e-mail or write me directly to let me know what you did or didn’t like
about this book—as well as what we can do to make our books stronger.
Please note that I cannot help you with technical problems related to the topic of
this book, and that due to the high volume of mail I receive, I might not be able
to reply to every message.
When you write, please be sure to include this book’s title and author as well as
your name and phone or fax number. I will carefully review your comments and
share them with the author and editors who worked on the book.
Fax: 317-581-4770
E-mail: graphics@samspublishing.com
{Part I }
Foundation
1 Flash Basics
2 What’s New in Flash 5
3 The Programmer’s Approach
4 Basic Programming in Flash
5 Programming Structures
6 Assigning Values
7 The Movie Clip Object
8 Functions
9 Selecting Text, Trapping Keys, and Manipulating
Strings
10 Arrays
11 Objects
12 Homemade Objects
13 Smart Clips
14 Interfacing with External Data
Discovering Diverse Content Through
Random Scribd Documents
LIBRARY.
No. 1.
EDMUND BURKE.
No. 2.
CHARLES JAMES FOX.
No. 3.
CARDINAL DE RETZ.
By Le Brun.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com