Tài liệu Actionscript 3.0 bible 2nd edition - Pdf 10

www.it-ebooks.info
www.it-ebooks.info
ActionScript
®
3.0 Bible
www.it-ebooks.info
www.it-ebooks.info
ActionScript
®
3.0 Bible
Second Edition
Roger Braunstein
Wiley Publishing, Inc.
www.it-ebooks.info
ActionScript
®
3.0 Bible
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-52523-4
Manufactured in the United States of America
10987654321
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

more. Additionally, he keeps busy with a series of independent projects. When not in front of a com-
puter, Roger enjoys normal human activities such as biking, cooking, reading, traveling, taking photos,
roller-skating, and dancing to music made on GameBoys. He is perpetually too preoccupied to put
anything interesting on his site
but you can use it to get in touch
with him.
www.it-ebooks.info
www.it-ebooks.info
Credits
Acquisitions Editor
Scott Meyers
Project Editor
Brian MacDonald
Technical Editor
Caleb Johnston
Production Editor
Daniel Scribner
Copy Editor
Karen Gill
Editorial Director
Robyn B. Siesky
Editorial Manager
Mary Beth Wakefield
Marketing Manager
David Mayhew
Production Manager
Tim Tate
Vice President and Executive
Group Publisher
Richard Swadley

for every problem. He was behind me and my ideas through thick and thin. His edits were always
spot-on. He was always available, always funny, and he even got my nerdy jokes. Trust me, if you’re
writing a programming book, bribe whoever you need to hire Brian.
I can’t talk about my team without mentioning the exhaustive copy editing done by Karen Gill. She
kept tabs on all my writing, cut down my useless tiresome redundant logorrhea, and made this book
less of a slog to get through. Trust me, you owe her one. I have the feeling her job is a little thankless,
but I do thank her.
Caleb Johnston, besides being a good friend, was a terrific technical editor. Somehow, with a full
course load for his master’s degree, he managed to find the time to review this entire book by him-
self. (The previous edition, although smaller, had three technical editors!) More than just scrutinizing
it, he made detailed and thoughtful criticisms, with as much ruthlessness as I demanded of him. He
found some quirky errors, and because he found them, you won’t have to.
Special thanks go out to my friend Corey Lucier at Adobe, who was kind enough to answer a few
questions about the internal workings of Flash Player or forward them on to Flash Player engineers.
Their additions helped me be even more accurate in this book, and Corey’s help was invaluable.
Special thanks also go to Whitney Gardner, who made two sublime illustrations for this book when I
was at my wit’s end.
Thanks to the U.S. economy for making my day job so unprofitable it made sense to sit in my
room and write for nine months. Thanks to coffee: you complete me. Thanks to my crazy SafeType
keyboard, which saved me from crippling arm pain. Thanks to my friends for, I dunno, whatever,
I like you.
Last but not least, thanks and lotsa lotsa love to my parents.
ix
www.it-ebooks.info
www.it-ebooks.info
Introduction xli
PartI:ActionScript3.0LanguageBasics 1
Chapter 1: Introducing ActionScript 3.0 3
Chapter 2: ActionScript 3.0 Language Basics 15
Chapter 3: Functions and Methods 39

xi
www.it-ebooks.info
Contents at a Glance
Chapter 29: Storing and Sending Data with SharedObject 571
Chapter 30: File Access 589
Part VII: Sound and Video 603
Chapter 31: Playing and Generating Sound 605
Chapter 32: Playing Video 625
Chapter 33: Capturing Sound and Video 643
Part VIII: Graphics Programming and Animation 655
Chapter 34: Geometric and Color Transformations 657
Chapter 35: Programming Vector Graphics 687
Chapter 36: Programming Bitmap Graphics 733
Chapter 37: Applying Filters 769
Chapter 38: Writing Shaders with Pixel Bender 803
Chapter 39: Scripting Animation 835
Chapter 40: Advanced 3D 855
PartIX:FlashinContext 877
Chapter 41: Globalization, Accessibility, and Color Correction 879
Chapter 42: Deploying Flash on the Web 897
Chapter 43: Interfacing with JavaScript 905
Chapter 44: Local Connections between Flash Applications 911
Index 921
xii
www.it-ebooks.info
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xli
Part I: ActionScript 3.0 Language Basics 1
Chapter 1: Introducing ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . 3
What Is ActionScript 3.0? 3
Exploring the Flash Platform 4

Contents
Commenting Your Code 20
Types of Comments 20
Single-Line Comment 20
Block Comments 20
XML Comments 20
Javadoc Comments 21
When to Use Comments 21
Self-Commenting Code 21
Introducing Scope 22
Introducing the Data Types 23
Declaring Types 23
Using Untyped Variables 23
Connecting You to an Operator 23
Unary vs. Binary Operators 24
Order of Operations 24
Some Commonly Used Operators 24
Assignment (=) 24
Arithmetic (+, –, *, /) 24
Modulo (%) 25
Increment (++) and Decrement (– –) 25
Compound Assignment Operators (+=, −=,*=,/=,and%=) 25
Comma Operator (,) 26
Making Logical Choices with Conditionals 26
if Statements 26
Equality (==) 27
Testing Other Comparisons 27
Greater Than (>)andLessThan(<) 28
Not Equal to (!=) 28
And (&&) and Or (||) Operators 28

Returning a Value Using a return Statement 45
Defining a Return Type for Your Function 46
Returning Void 46
Anonymous Functions 46
Functions as Objects 47
Recursive Functions 48
Summary 50
Chapter4:ObjectOrientedProgramming 51
Understanding Classes 51
Classes Can Model the Real World 51
Classes Contain Data and Operations 52
Classes Separate Responsibilities 52
Classes Are Types 52
Classes Contain Your Program 53
Object Oriented Terminology 53
Object 53
Class 54
Instance 54
Type 54
Encapsulation: Classes Are Like, So Selfish 55
The Black Box Principle 55
Encapsulation and Polymorphism 56
Packages: Classes, Functions, and Packing Peanuts 56
Class Uniqueness and Namespaces 56
Hierarchy 57
Controlling Visibility 58
Code Allowed in Packages 58
Using Code from Packages 59
Using Inheritance 61
Structuring Code with Inheritance 64

Chapter 5: Validating Your Program . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Introducing Errors 103
Compile-Time Errors vs. Runtime Errors 104
Compile-Time Errors 104
Runtime Errors 104
Warnings 104
Getting Feedback from Flash Professional and Flash Builder 104
Debugging in Flash Professional 104
Debugging in Flash Builder 106
Fixing Errors 108
Summary 110
Part II: Core ActionScript 3.0 Data Types 111
Chapter 6: Text, Strings, and Characters . . . . . . . . . . . . . . . . . . . . . . . 113
Working with String Literals 113
Using Escaped Characters 114
Converting to and from Strings 115
Using toString() 115
Casting and Converting to Strings 116
Converting Strings into Other Types 116
Converting Strings to Numbers 116
Converting Strings to Arrays 117
Combining Strings 118
Converting the Case of a String 118
Using the Individual Characters in a String 119
Getting the Number of Characters in a String 119
Getting a Particular Character 120
Converting a Character to a Character Code 120
Searching within a String 120
xvi
www.it-ebooks.info

Creating a Date 138
Epoch Time 139
Time zones 140
Accessing and Modifying a Date 141
Date Arithmetic 142
Execution Time 142
Formatting a Date 143
Summary 144
Chapter8:Arrays 145
Array Basics 145
Using the Array Constructor 145
Creating an Array by Using an Array Literal 147
Referencing Values in an Array 147
Finding the Number of Items in an Array 148
Converting Arrays to Strings 148
Adding and Removing Items from an Array 149
Appending Values to the End of Your Array with concat() 149
Applying Stack Operations push() and pop() 150
Applying Queue Operations shift() and unshift() 151
xvii
www.it-ebooks.info
Contents
Slicing, Splicing, and Dicing 152
Inserting and Removing Values with splice() 152
Working with a Subset of your Array with slice() 152
Iterating through the Items in an Array 153
Using a for Loop 153
Using for each in 154
Using the forEach() Method 154
Searching for Elements 155

Accessing Object Properties 182
toString() 183
Using Objects and Dictionaries as Associative Arrays 183
Comparing Arrays, Objects, and Dictionaries 184
Testing for Existence 186
Removing Properties 187
Iterating 188
xviii
www.it-ebooks.info
Contents
Using Objects for Named Arguments 188
Using Objects as Nested Data 189
XML as Objects 189
JSON 190
Summary 190
Chapter11:XMLandE4X 191
Getting Started with XML in ActionScript 191
XML References 191
E4X References 192
XML Literals 192
A Brief Introduction to E4X Operators and Syntax 194
Legacy XML Handling 195
Querying XML 196
The Child Axis 196
The Wildcard Operator 197
Indexed Elements 197
The Attribute Axis 198
The Text Axis 199
The Descendant Axis 200
The Parent Axis 201

Setting the Default XML Namespace 220
Querying XML for Namespaces 221
Additional Namespace Operations 222
Setting XML Options 223
Summary 223
Chapter12:RegularExpressions 225
Introducing Regular Expressions 225
Writing a Regular Expression 226
Applying Regular Expressions 226
String Methods and RegExp Methods 226
Testing 227
Locating 228
Identifying 229
Extracting 231
Replacing 233
Splitting 235
Constructing Expressions 235
Normal Characters 236
Dot Character 236
Escaped Characters 236
Metacharacters and Metasequences Demystified 237
Character Classes 238
Quantifiers 239
Anchors and Boundaries 240
Alternation 242
Groups 242
Regular Expression Flags 243
Global 243
Ignore Case 244
Multiline 244

Common Uses of ByteArrays 266
Loading Images 266
Copying Objects 267
Summary 268
Part III: The Display List 271
Chapter 14: Visual Programming with the Display List . . . . . . . . . . . . . 273
Introducing Display Lists and Display Objects 273
Structure of the Display List 274
Coordinate Spaces 274
Manipulating the Display List 276
Creating a New Display Object 276
Adding an Object to a Display List 277
Removing an Object from a Display List 278
Re-sorting Depths 278
Reparenting Display Objects 279
Examining Display Lists 279
Display Object Classes 280
DisplayObject 280
InteractiveObject 283
DisplayObjectContainer 283
Shape 284
Bitmap 284
Video 284
AVM1Movie 284
SimpleButton 284
TextField 285
Sprite 285
MovieClip 285
Loader 286
Stage 286

A Viewport Isn’t a Camera 305
Depths Are Managed by the DisplayObjectContainer 305
Other Missing Stuff 305
DisplayObject Revisited 306
Geometry Revisited 309
Mouse and Point Translation in 3D 311
Translating Points in Code 312
Modifying the Projection 314
Software 3D Libraries 318
Summary 319
Chapter 16: Working with DisplayObjects in Flash Professional . . . . . . 321
The Stage, Symbols, and the Library 321
Creating Symbols 322
Named Instances 323
Nested Instances 324
Associating Symbols to Classes 324
Writing an Associated Class 326
Nongraphic Symbol Types 326
Exporting and Using Assets 327
Using Assets from a SWC 327
Using Assets from a SWF 327
Summary 328
xxii
www.it-ebooks.info
Contents
Chapter17:Text,Styles,andFonts 329
Introducing TextFields 329
Creating a New TextField 330
Adding and Replacing Text 330
Setting a TextField’s Size 330

Making a TextField an Input Field 345
Restricting User Input 345
Tab-Accessible Input Text Fields 347
Password Text Fields 347
Interaction with TextField Events 347
focusIn and focusOut Events 347
Text Input Events 349
Link Events 352
Scroll Events 354
Interactive Typography 354
Text by Lines and Paragraphs 354
Finding Text by Location 356
xxiii
www.it-ebooks.info


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status