01 543547 FM.qxd 3/24/04 3:51 PM Page iii
Flash
™
MX 2004
ActionScript Bible
Robert Reinhardt and Joey Lott
01 543547 FM.qxd 3/24/04 3:51 PM Page ii
01 543547 FM.qxd 3/24/04 3:51 PM Page i
Flash
™
MX 2004
ActionScript Bible
01 543547 FM.qxd 3/24/04 3:51 PM Page ii
01 543547 FM.qxd 3/24/04 3:51 PM Page iii
Flash
™
MX 2004
ActionScript Bible
Robert Reinhardt and Joey Lott
01 543547 FM.qxd 3/24/04 3:51 PM Page iv
Flash™ MX 2004 ActionScript Bible
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2004 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
Library of Congress Control Number: 2004103173
ISBN: 0-7645-4354-7
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
1O/RU/QU/QU/IN
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of
the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through
payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978)
750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley
Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4447, E-Mail:
permcoordinator@
wiley.com
.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS
OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND
SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A
PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL
MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION.
THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL,
ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES
OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR
SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS
REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES
NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR
WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT
INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK
WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services or to obtain technical support, please contact our Customer
Care Department within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in
electronic books.
Trademarks: Wiley, the Wiley Publishing logo, and related trade dress are trademarks or registered trademarks of John
Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written
permission. Flash is a trademark of Macromedia, Inc. All other trademarks are the property of their respective owners.
Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.
Copyright © 1999–2003. Macromedia, Inc., 600 Townsend Street, San Francisco, CA 94103 USA. All Right Reserved.
Macromedia and Flash are trademarks or registered trademarks of Macromedia, Inc. in the United States and/or other
countries.
01 543547 FM.qxd 3/24/04 3:51 PM Page v
About the Authors
Robert Reinhardt, Director of Multimedia Applications for The Content Project (www
.contentproject.com), is internationally regarded as an expert on multimedia application
development, particularly in Macromedia Flash. Robert is the lead author of the Flash Bible
series and Flash ActionScript Bible (Wiley), as well as Macromedia MX: Building Rich Internet
Applications (Macromedia Press). He has developed multimedia courses for educational facili-
ties in Canada and the United States and has been a featured speaker at several Web confer-
ences. Robert also provides multimedia consulting through his company, [theMAKERS].
Joey Lott has written several books on Flash and ActionScript. He lives in Los Angeles.
01 543547 FM.qxd 3/24/04 3:51 PM Page vi
Credits
Executive Editor
Project Coordinator
Chris Webb
April Farling
Development Editor
Graphics and Production Specialists
Kezia Endsley
Beth Brooks
Lauren Goddard
Technical Editors
Joyce Haughey
Troy Gardner
Jennifer Heleine
Steve Nowicki
Kristin McMullan
Heather Ryan
Production Editor
Eric Newman
Special Help
Joni Burns
Copy Editors
Nancy Rapoport
Quality Control Technicians
Luann Rouff
John Greenough
Andy Hollandbeck
Editorial Manager
Luisa Perez
Mary Beth Wakefield
Carl Pierce
Charles Spencer
Vice President &
Executive Group Publisher
Permissions Editor
Richard Swadley
Laura Moss
Vice President and
Media Development Specialist
Executive Publisher
Angela Denny
Bob Ipsen
Proofreading and Indexing
Vice President and Publisher
TECHBOOKS Production Services
Joseph B. Wikert
Executive Editorial Director
Mary Bednarek
01 543547 FM.qxd 3/24/04 3:51 PM Page vii
To the future of expression on the Internet and the Web.
We owe it to ourselves to continually share our ideas
and experiences with one another.
— Robert
May there be peace within and among all beings.
May all recognize that which is.
— Joey
01 543547 FM.qxd 3/24/04 3:51 PM Page viii
01 543547 FM.qxd 3/24/04 3:51 PM Page ix
Foreword
F
lash has become an important and pervasive feature of the Web. Consider the numbers:
In June 2003 an NPD Research study showed that 97.4 percent of Web users have Flash
installed on their computer. The study was conducted roughly a year after the release of the
Flash Player 6 and showed that version 6 of the player was already available on more than
86 percent of Web users’ computers. The Flash Player is preinstalled in Internet Explorer and
other browsers. But that doesn’t explain why more than 86 percent of Web users had version
6 a year after its release. At the time, IDC Research estimated there were 448 million people
using the Web. A year after the release of the version 6 player, something like 386 million of
those people had version 6. The statistics don’t show how many people downloaded the
player and how many found that it came with their browser, but it’s a safe bet that hundreds
of millions of player downloads had to take place to get the player onto so many machines so
quickly.
The pervasiveness of the Flash Player has a lot to do with how widely Flash is used. But it is
not the only driving force. In 2003, during the course of history-making world events, large
media sites made extensive use of Flash to provide multimedia coverage of these events and
background information. At the same time, individuals created Flash animations and games
that were used to express views across the political spectrum. Flash was then, and is now, an
important vehicle for providing an expressive and dynamic Web. It is used for almost every-
thing. Advertisers love Flash advertisements because they are difficult to ignore. Educators
use Flash to create compelling online learning objects that enliven courses and provide online
simulations. Artists are always finding new uses for Flash, and institutions such as museums
rely on it more and more. Cartoonists continue to discover Flash and are constantly pushing
the envelope of animation length and quality. Flash front-ends to online applications are pop-
ping up everywhere and allow you to do everything from booking a hotel reservation to mak-
ing banking transactions.
The capacity of Flash to deliver compelling experiences on the Web encourages people to
download the latest player. In turn, the near ubiquity of the Flash Player encourages design-
ers and developers to make regular use of Flash. The two trends continue to feed off and
reinforce each other.
Internet technologies are constantly appearing, evolving, and in some cases disappearing.
Each new technology takes time to learn and apply effectively. As each technology evolves,
keeping up with it takes more time and effort, as does learning how to apply it to old prob-
lems and how to use it to solve new ones. At some point designers and developers have to
make big choices. It just isn’t possible to learn every Web technology in depth. After the
baseline requirements of learning HTML and style sheets, creating effective Web images, and
learning some JavaScript, what comes next? Just keeping up with the abbreviations can be
irritating. In no particular order: XML, XML-RPC, XUL, MXML, SQLXML, SVG, EPML, SMIL,
WSDL, SOAP, WAP, WMA, EJB, J2EE, SAX, JAX-RPC, LDAP, PHP, CFML, and on and on.
01 543547 FM.qxd 3/24/04 3:51 PM Page x
x
Foreword
Web designers and developers naturally gravitate to systems that are capable of reaching the
greatest number of people, provide the richest set of capabilities, and are still cost effective
to use. In other words, designers and developers need systems that provide ubiquity, utility,
and usability.
Flash has evolved from a vector-based animation tool to an amazingly rich, flexible, and
integrated design and development environment. Today you can seamlessly blend unique
vector-based animation with images, components such as the Datagrid and Tree components,
progressive download and streaming audio and video, real-time communications, and con-
nectivity to every type of enterprise-class computing system. Flash works with many of the
technologies already mentioned and provides some of its own for good measure, such as AMF
and RTMP. The power of the Flash authoring system does not lie only in the fact that it does
one or two things well. It delivers so many features in one integrated development and deliv-
ery system with which both designers and developers can effectively work. As Flash contin-
ues to evolve, the need to bring together a complex variety of difficult-to-integrate systems
and tools continues to diminish.
At the core of both the Flash development process and delivery system is the ActionScript
language and interpreter. Designers often make extensive use of ActionScript to simplify
their Flash movies and provide the kind of fine-grained control they need for visual elements.
Developers use ActionScript to make increasingly full-featured Web-based applications with
rich user interfaces and excellent responsiveness to the user’s actions. ActionScript can
accommodate the needs of both designers and developers because it is based on JavaScript
(also known as ECMAScript).
ECMAScript/JavaScript is first and foremost a scripting language. It was designed from the
beginning to provide easy-to-use object scripting capabilities. In Flash, that means it is rela-
tively simple to do things such as attach a behavior to a button that in turns manipulates
another object such as an animation running within a Movie Clip. The ActionScript code to
add a behavior that manipulates an object is short and simple, and the Flash authoring envi-
ronment makes it easier still. However, ActionScript is not restricted to scripting objects. It is
possible to build large and complex applications using traditional object-oriented design and
development methods that are realized in ActionScript. With the release of the 2004 Flash
products, ActionScript has evolved further to increase support for advanced object-oriented
development without sacrificing the language’s utility for designers.
Learning to work with ActionScript is an essential Flash skill. How far you go with ActionScript
and how you approach learning the language will vary depending on your background —
especially how much computer programming you already know. However you approach
learning ActionScript, you will constantly be working with both the language and the objects
it allows you to manipulate — especially Movie Clips. Flash MX 2004 ActionScript Bible provides
an excellent roadmap to the language and the variety of objects it allows you to create and
manipulate. The two authors bring a great deal of practical experience to the book and are
also accomplished teachers and learners. I first met Robert Reinhardt when he was a first-
year student at Ryerson University. Robert was the kind of student professors pray for. He is
intelligent, inquisitive, and remarkably energetic. As I have with so many students who have
graduated from Ryerson, I completely lost track of Robert after he got his degree. Some years
later when I finally decided to learn something about Flash I asked one of my colleagues which
book I should read. I was told to buy Reinhardt and Lentz’s Flash 4 Bible. When I realized that
01 543547 FM.qxd 3/24/04 3:51 PM Page xi
Foreword
xi
I knew one of the authors, I was delighted. But I was not surprised by the high quality of
Robert’s work. Some time later Robert met Joey Lott while teaching a class on Flash. Joey
stood out for Robert in much the same way Robert stood out for me. Joey has moved on to
write a number of books on different facets of programming in Flash and with Robert has
produced a book I’m happy to sneak my name into by writing these few pages. Flash MX 2004
ActionScript Bible shows a concern for the needs of designers and developers who want to
learn ActionScript through experimentation and exploration. Enjoy.
Brian Lesser
Assistant Director, Teaching and Technology Support
Computing and Communications Services
Ryerson University, Toronto, Canada
01 543547 FM.qxd 3/24/04 3:51 PM Page xii
01 543547 FM.qxd 3/24/04 3:51 PM Page xiii
Preface
I
f you’ve picked up this book, then you are undoubtedly familiar with Flash. Since Macromedia
first acquired the program, Flash has become increasingly popular to the point where there
are few people who don’t know what Flash is. Flash applications, sometimes referred to as
Flash movies, can be deployed in many types of environments. But by far the most popular
use of Flash is on the Web. The reason is simple: Flash provides a much more robust and
interactive experience than HTML can. The opportunities that Flash provides appeal to a wide
audience — from artists to corporations. It offers a medium for expressing creativity, ideas,
and messages in unique and innovative ways. Whether it is an artist wanting to create inter-
active art, an organization wanting to provide resources and information, a company wanting
to sell products, a group wanting to create a real-time interactive community, or a university
wanting to create collaborative learning experiences, Flash is the medium of choice.
But as Flash has evolved, and as the demands of the community have grown, so have the
complexities and intricacies of the application. This is true of ActionScript more than any
other aspect of Flash. In its early versions ActionScript, the programming language within
Flash, consisted of nothing more than a few commands that could be applied via menus only.
Flash 5 marked a huge step in the evolution of ActionScript. In Flash MX, ActionScript adapted
to the wants of the developers by providing more programmatic control within a Flash appli-
cation. And Flash MX 2004 represents another big leap in ActionScript.
Using Flash MX 2004, you can do a great many things programmatically. All of the ActionScript-
based features from previous versions of Flash are still available. For example, you can still
send and load variables and XML and use Flash Remoting. You can still load MP3s at runtime.
You can still load SWF and JPEG content, but Flash MX 2004 provides you with an improved
way of doing so. Using Flash MX 2004 you can still display HTML, but new is the cascading
style sheet (CSS) support that enables you to effectively apply formatting. Flash MX 2004
replaces the older printing functions with the new
PrintJob class to afford you more control.
The list goes on and on. In fact, it took us an entire book to provide you with all the information!
Macromedia Flash MX ActionScript Bible was the first edition, and we’ve updated it to produce
this second edition. But this book is much more than just a basic update to its previous incar-
nation. Although we made every effort to make the first edition as good as possible, in the time
that has passed since its publication, we have learned a lot. We’ve listened to your feedback.
And we think you will find that this new edition is filled with valuable and accurate informa-
tion that is well organized, readable, and practical. We’ve done our best to provide in-depth
research combined with practical, working knowledge.
Some of the features you’ll find in this book are:
✦ Comprehensive coverage of ActionScript: We’ve included just about everything you
could think of, and a few things you probably didn’t think of. We’ve attempted to make
sure the information is relevant, practical, and significantly more than just a basic refer-
ence. We have included coverage of basic ActionScript syntax; all the built-in commands,
functions, and classes; and even some coverage of related technologies such as Flash
Remoting.
01 543547 FM.qxd 3/24/04 3:51 PM Page xiv
xiv
Preface
✦ Complete coverage of ActionScript 2.0: ActionScript 2.0 is new in Flash MX 2004, and
we’ve detailed it in depth. You’ll find descriptions of the syntax, best practices, and
beginner, intermediate, and advanced topics.
✦ Working examples and exercises: We know that one of the best ways to learn
ActionScript is to practice writing it. So throughout the chapters you can find lots of
exercises that you can use to practice the concepts as you read them. You’ll find the
completed files on the CD-ROM that accompanies this book in case you get stuck and
want to see the working examples.
✦ Practical expertise and advice: Theory is useful up to a point. But if you want to use
Flash and ActionScript to build a working application, you’ll need more than that. While
we provide all the theory, we also back it up with explanations, tips, and advice based
on practical experience building professional applications.
✦ Continuing community and support: The official Web site for the book is
www.
flashsupport.com. There you’ll find updates and notes about the book as well as
support forums for readers so you can ask any questions you might have.
We encourage your feedback. In fact, we’ve set up a system so that you can submit feedback
on specific chapters. Your comments will help us make the next edition even better. You can
find the feedback application at
www.flashsupport.com/feedback.
How to Get the Most Out of This Book
You can read and utilize this book in many ways. If you are a beginning programmer or even
if you’re just new to ActionScript, we encourage you to read Parts I and II first. We also recom-
mend that you read Chapter 9. Following that, you can browse the chapters and sections that
most interest you. ActionScript is a large subject, and you will likely find that you will master
one part at a time.
If you already know ActionScript from previous versions of Flash, but you don’t yet know
ActionScript 2.0, you will likely find it helpful to follow the same advice that we offer to begin-
ning coders. Part II is probably the most important section for you to start with, however.
Intermediate and advanced ActionScript developers can still benefit from the book. You can
turn to any chapter for a reference. For example, even an advanced ActionScript developer
might not necessarily know all the details about a particular class. If you want to learn more
about a class, or just brush up on it, read the chapter for reference.
Keep the book on your desk. Read sections over and over. Try the exercises. You’ll learn more
each time. At first, just getting a
MovieClip object to move across the screen may be difficult.
But upon returning to that section months later, you will undoubtedly discover something
you didn’t notice before.
Conventions Used in the Book
Throughout the book when we refer to application menus, the menu names and nested menu
items are separated by arrow icons. For example, to open a new Flash document within Flash
MX 2004 you can select the New option from the File menu. We indicate that in the text by
suggesting you choose File ➪ New.
01 543547 FM.qxd 3/24/04 3:51 PM Page xv
Preface
xv
Web
Resource
On the
CD-ROM
New
Feature
Cross-
Reference
Caution
Note
Tip
Although the icons are pretty standard and self-explanatory (they have self-explanatory
labels), here’s a brief explanation of what they are and what they mean.
Tips offer you extra information that further explains a given topic or technique, often sug-
gesting alternatives or workarounds to a listed procedure.
Notes provide supplementary information to the text, shedding light on background pro-
cesses or miscellaneous options that aren’t crucial to the basic understanding of the material.
When you see the Caution icon, make sure you’re following along closely to the tips and
techniques being discussed. Some external applications might not work exactly the same
with Flash on different operating systems.
If you want to find related information to a given topic in another chapter or section, look
for the cross-reference icon.
The New Feature icons point out any differences between Flash MX 2004 and ActionScript
2.0 and previous versions.
This icon indicates that the CD-ROM contains a related file in the given folder.
When you see this icon, you will find Web URLs that point to further information about the
topic at hand.
Also, many code samples that are printed in this book have lines of code that are too long to
fit on one line. These lines of code are broken into two or more lines and end with the line
continuation symbol,
Æ. This symbol should not be typed into the actual code of your Flash
document. Simply continue to type the following line(s) of code on the same line in the
Actions panel. For example, you would type the following line all on the same line in the
Actions panel:
mcPhoto._accProps.description = “Picture of attendees at the round table
Æ
discussion”;
Because Flash MX 2004 is available for both the Windows and Mac OS X operating systems,
when applicable we provide keyboard shortcuts for both. In many cases the Ctrl key in a
Windows environment is analogous to the Command key on the Macintosh, which we repre-
sent using the Ô symbol. You’ll also notice that many keyboard shortcuts are denoted using
a + symbol when Flash requires that you press several keys at the same time. For example,
the notation Shift+N indicates that you should press and hold the Shift key while then press-
ing the N key.
01 543547 FM.qxd 3/24/04 3:51 PM Page xvi
xvi
Preface
How This Book Is Organized
We’ve reorganized this edition of the book in ways that we think will make it most approach-
able and helpful. The ten parts of the book are outlined in the following sections.
Part I: Conceptualizing Flash
When you are first starting to develop ActionScript-rich Flash applications, you’ll want to make
sure that you are planning the projects appropriately. Part I provides you with the information
you need to put Flash into the context of application development, and it helps you to plan your
projects appropriately.
Part II: Laying the ActionScript Foundation
When you build a building, the first thing you do is lay the foundation. Doing so helps to
ensure a sturdy base from which something can be created. Part II aims to provide you with
the basic information and practical exercises that can assist you in getting a fundamental
understanding of ActionScript. You’ll learn all about how ActionScript works, where to place
it, how to write it, syntax, structure, and much more.
Part III: MovieClip, Button, and Drawing API
The MovieClip class is one of the primary classes in ActionScript. Part III introduces you to
the
MovieClip class (which includes the Drawing API — which enables you to draw program-
matically). And because the
Button class is so closely related to MovieClip, you will also
learn all about how to use the
Button class as well.
Part IV: The Core Classes
The core classes provide important, yet non-visual functionality within your Flash applica-
tions. The classes include
Array for grouping and indexing data, Math for performing
advanced mathematical operations,
Date for working with date and time values, String for
working with textual values, and the wrapper classes
Number and Boolean. Part IV looks at
each of these classes (and related functions) in depth.
Part V: The Movie Classes
Part V looks at each of the classes that have some kind of visual representation within an
application (minus
MovieClip and Button, which are discussed in Part III) or handles user
interaction within the application. This group includes classes such as
Color for adjusting
color and
TextField for working with visual text. It also includes other assorted classes such
as
Mouse for working with the mouse interaction, ContextMenu for controlling the items in
the right-click/Ô-click menu, and
PrintJob for printing Flash content.
Part VI: The Audio and Video Classes
Flash MX 2004 has increased multimedia support. The Sound class is supported as previously.
In addition, Flash MX 2004 enables you to load FLV video files programmatically without the
01 543547 FM.qxd 3/24/04 3:51 PM Page xvii
Preface
xvii
use of Flash Communication Server. This functionality is provided by means of the NetStream
and Video classes. Part VI provides complete coverage of the Sound, NetStream, and Video
classes.
Part VII: The Data Classes
Although Flash was originally an animation medium, it has steadily grown to supported
more and more data capabilities. In Part VII you can read about the classes that support
sending and loading data, including coverage of the
SharedObject, LocalConnection, XML,
LoadVars, and XMLSocket classes.
Part VIII: Using Components
Components are an important part of Flash MX 2004. By encapsulating functionality, compo-
nents can provide a simple drag and drop solution to what might otherwise require hundreds
or even thousands of lines of code. In Part VIII you’ll learn about the user interface components
that are included with Flash as well as how to create your own components.
Part IX: Working with Flash in Other Environments
Part IX discusses how Flash can interact with the environment in which it is being played
back. For example, you’ll get a chance to learn how to use Flash within a Web browser as well
as how you can issue special commands when publishing a stand-alone player version of
your application.
Part X: Creating Flash Applications
Once you’ve learned the basics, Part X shows you how to put it all together when creating
complete applications. You’ll get a chance to read about how to optimize and manage the
download and presentation of content, special tips for working with data exchange, working
with Web services, and creating user input forms with Flash.
CD-ROM Chapter
Be sure to check the CD-ROM for an additional chapter that wasn’t added to the printed ver-
sion of the book. You’ll find extra information such as how to perform pattern matching using
the
RegExp class.
Appendix
The appendix contains information regarding the CD-ROM that accompanies this book.
Getting in Touch with Us
The official Web site for this book is:
www.flashsupport.com
01 543547 FM.qxd 3/24/04 3:51 PM Page xviii
xviii
Preface
At the site you’ll find updates, notes, and more. Additionally, you can find support forums so
you can post and answer questions and get to know others in the Flash Bible and ActionScript
Bible community.
We appreciate your feedback. If you have found this book to be helpful, please let us know.
And if you have suggestions for ways we might improve subsequent editions, please let us
know that as well. You can contact us by e-mail at the following addresses:
✦ Robert:
✦ Joey:
Getting in Touch with Macromedia
Macromedia wants to constantly improve Flash in ways that help you. The only way they get
to know how you are using Flash (or how you’d like to use Flash) is if you send them feed-
back. The more feedback you can provide to them, the better equipped they are to adapt
Flash to your requests. In order to hear from you, Macromedia has set up a system by which
you can submit your feedback at:
www.macromedia.com/support/email/wishform/?6213=9
If there are features that work particularly well for you, let them know. If there are features
that are not working for you, let them know. And if there are things that Flash does not do
that you’d like it to do, then let Macromedia know that as well.
To support the Flash community Macromedia has created a searchable registry that allows
clients to find Flash developers by location or by services offered. To create a custom devel-
oper profile, register yourself at:
www.macromedia.com/locator
Regardless of your geographic location, you always have access to the global Flash community
for support and the latest information through the Macromedia Online Forums:
You can also visit Macromedia’s new Designer & Developer Center, where you can find the
latest news and tutorials for Macromedia MX software:
www.macromedia.com/devnet
For inspiration and motivation, check out the site of the day, weekly features, and case stud-
ies at:
www.macromedia.com/showcase
01 543547 FM.qxd 3/24/04 3:51 PM Page xix
Acknowledgments
T
his book represents the collective efforts of many people, all of whom have contributed
in some way to make it as good as it can be. We thank everyone at John Wiley & Sons for
helping with each step of the process. Thanks go to Chris Webb, the acquisitions editor for
this project, for his guidance and assistance, and for acting as a liaison to make sure that the
best interests of the book were kept in mind at the publisher. This book is also, in large part,
made possible by Kezia Endsley, our development editor, who has gone over every word,
coordinated schedules, and ensured that the book is of the highest quality possible. Thank
you, Kezia.
We thank our agent, David Fugate, for being there and for assisting when needed.
Of course, this book about Flash wouldn’t even exist without the hard work of the people at
Macromedia who continue to develop and promote Flash. Many thanks to the developers,
engineers, and support staff at Macromedia. Particularly we thank Lucian Beebe, Gary
Grossman, Nigel Pegg, Nivesh Rajbhandari, Erica Norton, Mike Shroeder, Barbara Herbert,
and Heather Hollaender.
Troy Gardner and Steve Nowicki provided their support throughout the book by editing the
chapters for technical content. Thank you, Troy and Steve, for double-checking all the code
and all of our claims to make sure that the book is as technically accurate as it can be.
Many thanks are due to the many developers, designers, artists, coders, and other members
of the Flash community. You’ve pushed the limits. You’ve innovated. You’ve inspired. In par-
ticular we thank those people with whom we have shared dialogues throughout the writing of
this book. Thanks go to Peter and Jen deHaan, Chafic Kazoun, Tom Muck, and Shane Elliott.
We especially thank you. It is the readers who make this book what it is. Thank you for your
questions, your comments, and your feedback.
Robert’s acknowledgments: I couldn’t have completed this revised edition without my part-
ner, Snow Dowd. I thank her for her encouragement and support during the long nights and
lost weekends I spent updating this book. I extend my deepest gratitude to Joey Lott, whose
vast knowledge of Flash programming makes this book the valuable resource that it is. I also
thank all of the wonderful people at The Content Project who have enriched my breadth and
depth of Flash design and programming. Without their collaboration, I wouldn’t have as many
exciting opportunities to push the limits of Flash experiences.
Joey’s acknowledgments: I thank Robert for having offered me the opportunity to write this
book with him. I’d like to thank my parents and sister for their love and support. I’d like to
give thanks to that which cannot be put into words — that which is the very essence of all
being.
01 543547 FM.qxd 3/24/04 3:51 PM Page xx
Contents at a Glance
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Part I: Conceptualizing Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 1: An Introduction to Flash MX 2004 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Chapter 2: Working with Web Technologies and Interactive Models . . . . . . . . . . . . . . 19
Chapter 3: Architecture for Flash Movies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Part II: Laying the ActionScript Foundation . . . . . . . . . . . . . . . . . . . 63
Chapter 4: Learning ActionScript Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Chapter 5: Constructing ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Chapter 6: Working with Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Chapter 7: Programming with Objects and Classes . . . . . . . . . . . . . . . . . . . . . . . 143
Chapter 8: Error Handling and Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Part III: MovieClip, Button, and Drawing API . . . . . . . . . . . . . . . . . . 217
Chapter 9: MovieClip and Button Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Chapter 10: The Drawing API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Part IV: The Core Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Chapter 11: Using the Array Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
Chapter 12: The Number Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Chapter 13: The Math Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Chapter 14: Working with Dates and Times . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
Chapter 15: Working with Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Part V: The Movie Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Chapter 16: The Color Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Chapter 17: The TextField and Selection Classes . . . . . . . . . . . . . . . . . . . . . . . . 395
Chapter 18: Using the TextFormat Object and Style Sheets . . . . . . . . . . . . . . . . . . 441
Chapter 19: The Mouse and Key Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Chapter 20: The Stage and ContextMenu Classes . . . . . . . . . . . . . . . . . . . . . . . . 503
Chapter 21: The System Class and the Capabilities and Security Objects . . . . . . . . . . 529
Chapter 22: The PrintJob Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
01 543547 FM.qxd 3/24/04 3:51 PM Page xxi
Part VI: The Audio and Video Classes . . . . . . . . . . . . . . . . . . . . . . 561
Chapter 23: The Sound Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
Chapter 24: The NetStream and Video Classes . . . . . . . . . . . . . . . . . . . . . . . . . 599
Part VII: The Data Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613
Chapter 25: The SharedObject and LocalConnection Classes . . . . . . . . . . . . . . . . . 615
Chapter 26: The XML and LoadVars Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
Chapter 27: The XMLSocket Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657
Part VIII: Using Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671
Chapter 28: Using V2 UI Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
Chapter 29: UI Component Style and Focus Management . . . . . . . . . . . . . . . . . . 731
Chapter 30: Creating Your Own Components . . . . . . . . . . . . . . . . . . . . . . . . . . 745
Part IX: Working with Flash in Other Environments . . . . . . . . . . . . . . 767
Chapter 31: Working with Flash in the Web Browser . . . . . . . . . . . . . . . . . . . . . . 769
Chapter 32: Making Movies Accessible and Universal . . . . . . . . . . . . . . . . . . . . . 779
Chapter 33: Scripting for the Flash Stand-Alone Player . . . . . . . . . . . . . . . . . . . . 795
Part X: Creating Flash Applications . . . . . . . . . . . . . . . . . . . . . . . . 811
Chapter 34: Managing and Loading Flash Content . . . . . . . . . . . . . . . . . . . . . . . 813
Chapter 35: Sending and Loading Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847
Chapter 36: Using the Built-In Web Service Functionality . . . . . . . . . . . . . . . . . . . 865
Chapter 37: Making Flash Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 873
Chapter 38: Using the RegExp Class . . . . . . . . . . . . . . . . . . . . . . . . On the CD-ROM
Appendix A: What’s on the CD-ROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 889
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 893
01 543547 FM.qxd 3/24/04 3:51 PM Page xxii