Colin Moock0596526946, 9780596526948
Table of contents :
Essential ActionScript 3.0……Page 1
Table of Contents……Page 6
Foreword……Page 16
Beginners Welcome……Page 20
What’s In This Book……Page 21
ActionScript Overview……Page 22
The Core Language……Page 23
Flash Runtime Clients……Page 24
Components……Page 25
ActionScript Development Tools……Page 26
Typographical Conventions……Page 27
How to Contact Us……Page 29
Acknowledgments……Page 30
Part I ActionScript from the Ground Up……Page 34
Tools for Writing ActionScript Code……Page 36
Flash Client Runtime Environments……Page 37
Just-In-Time Compilation……Page 38
Classes and Objects……Page 39
Creating a Program……Page 41
Packages……Page 42
Defining a Class……Page 44
Access Control Modifiers for Classes……Page 45
Virtual Zoo Review……Page 46
Constructor Methods……Page 47
Literal Syntax……Page 49
Object Creation Example: Adding a Pet to the Zoo……Page 50
Local Variables……Page 52
Instance Variables……Page 53
Access-control modifiers for instance variables……Page 55
Constructor Parameters and Arguments……Page 57
Expressions……Page 59
Assigning One Variable’s Value to Another……Page 61
Copies and References……Page 62
An Instance Variable for Our Pet……Page 63
Instance Methods……Page 64
Access Control Modifiers for Instance Methods……Page 67
Method Parameters and Arguments……Page 69
Method Return Values……Page 71
Method Signatures……Page 74
Virtual Zoo Review……Page 75
Break Time!……Page 76
The if Statement……Page 77
Chaining if statements……Page 80
The switch Statement……Page 81
The while Statement……Page 83
Processing Lists with Loops……Page 85
The do-while Statement……Page 89
The for Statement……Page 90
Logical OR……Page 91
Logical AND……Page 93
Logical NOT……Page 94
Back to Classes and Objects……Page 95
Instance Methods Revisited……Page 96
Omitting the this Keyword……Page 97
Managing Parameter/Variable Name Conflicts……Page 98
Bound Methods……Page 99
Using Methods to Examine and Modify an Object’s State……Page 101
Get and Set Methods……Page 105
Handling an Unknown Number of Parameters……Page 108
Up Next: Class-Level Information and Behavior……Page 109
Static Variables……Page 110
Constants……Page 113
Static Methods……Page 115
The Class Initializer……Page 117
Class Objects……Page 118
On to Functions……Page 119
Functions……Page 120
Package-Level Functions……Page 121
Global Functions……Page 122
Nested Functions……Page 123
Source-File-Level Functions……Page 124
Accessing Definitions from Within a Function……Page 125
Function Literal Syntax……Page 126
Recursive Functions……Page 128
Using Functions in the Virtual Zoo Program……Page 129
Back to Classes……Page 133
A Primer on Inheritance……Page 134
Static Methods and Static Variables Not Inherited……Page 137
Overriding Instance Methods……Page 138
Invoking an Overridden Instance Method……Page 140
Constructor Methods in Subclasses……Page 141
Preventing Classes from Being Extended and Methods from Being Overridden……Page 145
Subclassing Built-in Classes……Page 146
Why Inheritance?……Page 147
Polymorphism and Dynamic Binding……Page 148
Inheritance Versus Composition……Page 150
When to use composition over inheritance……Page 152
Abstract Not Supported……Page 153
Creating Types of Pet Food……Page 154
Preparing VirtualZoo for Onscreen Display……Page 158
Virtual Zoo Program Code……Page 159
It’s Runtime!……Page 162
Compiling with the Flash Authoring Tool……Page 163
Compiling the Program……Page 164
Running the Program……Page 165
Compiling with mxmlc……Page 166
The Compilation Process and the Classpath……Page 167
Strict-Mode Versus Standard-Mode Compilation……Page 168
The Fun’s Not Over……Page 169
Datatypes and Type Checking……Page 170
Datatypes and Type Annotations……Page 171
Compatible Types……Page 172
Detecting Type Mismatch Errors with Type Annotations……Page 173
Untyped Variables, Parameters, Return Values, and Expressions……Page 175
Strict Mode’s Three Special Cases……Page 176
Warnings for Missing Type Annotations……Page 177
Detecting Reference Errors at Compile Time……Page 178
Casting……Page 179
Avoiding Unwanted Type Mismatch Errors……Page 180
Upcasting and Downcasting……Page 181
Using the as Operator to Cast to Date and Array……Page 182
Conversion to Primitive Types……Page 183
null and undefined……Page 186
Datatypes in the Virtual Zoo……Page 187
More Datatype Study Coming Up……Page 191
The Case for Interfaces……Page 192
Interfaces and Multidatatype Classes……Page 194
Interface Syntax and Use……Page 195
Interface Inheritance……Page 197
Another Multiple-Type Example……Page 198
More Essentials Coming……Page 204
Statements……Page 205
Operator Precedence……Page 207
Operator Associativity……Page 208
Datatypes and Operators……Page 209
Operator Overview……Page 210
Up Next: Managing Lists of Information……Page 218
What Is an Array?……Page 219
Creating Arrays with Array Literals……Page 220
Retrieving an Element’s Value……Page 222
Setting an Element’s Value……Page 223
Determining the Size of an Array……Page 224
Adding New Elements with the length Variable……Page 226
The unshift() method……Page 227
The splice() method……Page 229
Removing Elements from an Array……Page 230
The pop() method……Page 231
Checking the Contents of an Array with the toString() Method……Page 232
Multidimensional Arrays……Page 233
On to Events……Page 234
ActionScript Event Basics……Page 235
Registering an Event Listener for an Event……Page 236
Step 2: Determine the event object’s datatype……Page 237
Step 4: Register for the event……Page 238
Two More Event Listener Registration Examples……Page 239
Unregistering an Event Listener for an Event……Page 241
Accessing the Target Object……Page 242
Accessing the Object That Registered the Listener……Page 245
Preventing Default Event Behavior……Page 246
Event Listener Priority……Page 247
Event Listeners and Memory Management……Page 249
Weak Listener References……Page 253
Custom Events……Page 254
A Custom “gameOver” Event……Page 255
A Custom “toggle” Event……Page 258
Preventing Default Behavior for Custom Events……Page 261
Type Weakness in ActionScript’s Event Architecture……Page 266
Module.swf Listener Registers with Main.swf Object……Page 269
Main.Swf Listener Receives Notification for an Event Targeted at a Module.swf Display Object……Page 270
An Alternative to allowDomain(): Shared Events……Page 271
What’s Next?……Page 273
The Exception-Handling Cycle……Page 274
Handling Multiple Types of Exceptions……Page 277
Determining Exception Type Granularity……Page 279
Options 1 and 2: Using a single custom-exception type……Page 281
Option 3: Using configurable debugging messages……Page 282
Option 4: Multiple custom VirtualPetNameException subclasses……Page 283
Exception Bubbling……Page 286
Uncaught Exceptions……Page 290
The finally Block……Page 291
Nested Exceptions……Page 293
Control-Flow Changes in try/catch/finally……Page 297
Error Events for Problem Conditions……Page 300
More Gritty Work Ahead……Page 301
Eligibility for Garbage Collection……Page 302
Incremental Mark and Sweep……Page 305
Disposing of Objects Intentionally……Page 306
Deactivating Objects……Page 307
Garbage Collection Demonstration……Page 310
On to ActionScript Backcountry……Page 311
Dynamic ActionScript……Page 312
Dynamic Instance Variables……Page 313
Processing Dynamic Instance Variables with for-each-in and for-in Loops……Page 315
Dynamically Adding New Behavior to an Instance……Page 317
Dynamic References to Variables and Methods……Page 319
Using Dynamic Instance Variables to Create Lookup Tables……Page 320
Using Functions to Create Objects……Page 322
Using Prototype Objects to Augment Classes……Page 324
The Prototype Chain……Page 325
Onward!……Page 327
Scope……Page 328
Global Scope……Page 329
Class Scope……Page 330
Instance Method Scope……Page 331
Function Scope……Page 332
The Internal Details……Page 333
Expanding the Scope Chain via the with Statement……Page 335
On to Namespaces……Page 336
Namespace Vocabulary……Page 337
ActionScript Namespaces……Page 338
Defining the Namespace……Page 340
Namespace Terminology Review……Page 342
Using a Namespace to Qualify Variable and Method Definitions……Page 343
User-Defined Namespace Attributes in the Top-Level of a Class Only……Page 344
Qualified Identifiers……Page 345
A Functional Namespace Example……Page 347
Accessibility of Package-Level Namespace Definitions……Page 350
Accessibility of Class-Level Namespace Definitions……Page 351
Accessibility of Function-Level Namespace Definitions……Page 353
Qualified-Identifier Visibility……Page 354
Comparing Qualified Identifiers……Page 355
Assigning a Namespace Value to a Variable……Page 356
A Namespace Value Example……Page 358
Open Namespaces and the use namespace Directive……Page 367
Open Namespaces and Scope……Page 368
Opening Multiple Namespaces……Page 370
Namespaces for Access-Control Modifiers……Page 371
Import Opens Public Namespaces……Page 373
Example: Framework-Internal Visibility……Page 374
Example: Permission-Based Access Control……Page 375
Example: Program Modes……Page 379
Final Core Topics……Page 385
Understanding XML Data as a Hierarchy……Page 386
Representing XML Data in E4X……Page 388
Creating XML Data with E4X……Page 390
Accessing the Root XML Node……Page 392
Accessing Child Nodes……Page 393
Accessing Text Nodes……Page 395
Accessing Parent Nodes……Page 398
Accessing Sibling Nodes……Page 399
Accessing Attributes……Page 400
Accessing Comments and Processing Instructions……Page 403
Accessing Attributes and Elements Whose Names Contain Reserved Characters……Page 404
Treating XMLList as XML, Revisited……Page 405
Processing XML with for-each-in and for-in……Page 410
Accessing Descendants……Page 412
Filtering XML Data……Page 416
Traversing XML Trees……Page 419
Changing the Contents of an Element……Page 420
Changing an Attribute Value……Page 421
Replacing an Entire Element……Page 422
Adding New Attributes and Elements……Page 423
Adding a new child after all existing children……Page 424
Adding a new child after a specific existing child……Page 425
Adding a new child before all existing children……Page 426
References to Parts of a Document Are Not Live……Page 427
Using XML Entities for Special Characters……Page 428
Assigning Values to an XMLList……Page 429
Loading XML Data……Page 430
Accessing Namespace-Qualified Elements and Attributes……Page 431
Creating Namespace-Qualified Elements and Attributes……Page 435
Converting XMLList to a String……Page 437
Converting an XML Element to a String……Page 438
Converting Comments and Processing-Instructions to Strings……Page 439
XML Equality……Page 440
XMLList Equality……Page 441
QName Equality……Page 442
More to Learn……Page 443
Flash Player Security Restrictions……Page 444
The Local Realm, the Remote Realm, and Remote Regions……Page 445
Security-Sandbox-Types……Page 446
How Security-Sandbox-Types Are Assigned……Page 447
Security Generalizations Considered Harmful……Page 448
Loading Content……Page 449
Loading Data……Page 450
Restrictions on Loading Content, Accessing Content as Data, Loading Data, and Cross-Scripting……Page 451
Example Security Scenarios……Page 455
Snoopy Email Attachment—With Flash Player Security……Page 456
Cross-Web Site Information—Without Flash Player Security……Page 457
Compiling a Local-with-Filesystem .swf File……Page 458
Compiling a Local-with-Networking .swf File……Page 459
Granting Local Trust……Page 460
Developers Automatically Trusted……Page 461
Distributor Permissions (Policy Files)……Page 462
Creating the policy file……Page 464
Posting the policy file……Page 465
Obtaining a policy file’s permission to load data……Page 466
Obtaining a policy file’s permission to access content as data……Page 468
Using a Policy File to Authorize Socket Connections……Page 471
Create the policy file……Page 472
Socket-based policy-file retrieval……Page 473
HTTP-based policy-file retrieval……Page 475
Creator Permissions (allowDomain())……Page 477
Import Loading……Page 479
Handling Security Violations……Page 481
Security Domains……Page 483
Ambiguous Use of the Term “Sandbox”……Page 484
Two Common Security-Related Development Issues……Page 485
Accessing the Loader Class’s Instance Variable Content……Page 486
On to Part II!……Page 487
Part II Display and Interactivity……Page 488
The Display API and the Display List……Page 490
Display API Overview……Page 491
Extending the Core-Display Class Hierarchy……Page 494
The Display List……Page 495
Containers and Depths……Page 502
Removing Assets from Containers……Page 508
Removing Assets from Memory……Page 509
Removing All Children……Page 510
Reparenting Assets……Page 511
Traversing Objects in a Display Hierarchy……Page 513
Manipulating Objects in Containers Collectively……Page 515
Descendant Access to a .swf File’s Main Class Instance……Page 517
Whither _level0?……Page 519
Containment Events……Page 520
The Event.ADDED and Event.REMOVED Events……Page 521
A Real-World Containment-Event Example……Page 525
The ADDED_TO_STAGE and REMOVED_FROM_STAGE Events……Page 526
Custom Event.ADDED_TO_STAGE and Event.REMOVED_FROM_STAGE events……Page 528
Custom Graphical Classes……Page 532
Go with the Event Flow……Page 534
Hierarchical Event Dispatch……Page 535
Event Dispatch Phases……Page 536
Event Listeners and the Event Flow……Page 538
Registering an Ancestor Listener for the Capture Phase……Page 539
Registering an Ancestor Listener for the Bubbling Phase……Page 540
Registering an Ancestor Listener for Both the Capture Phase and the Bubbling Phase……Page 541
The Dual Purpose of the useCapture Parameter……Page 542
Removing Event Listeners……Page 543
Using the Event Flow to Centralize Code……Page 544
Determining the Current Event Phase……Page 547
Distinguishing Events Targeted at an Object from Events Targeted at That Object’s Descendants……Page 549
Stopping an Event Dispatch……Page 551
Event Priority and the Event Flow……Page 555
Display-Hierarchy Mutation and the Event Flow……Page 556
Event Listener List Mutation……Page 558
Custom Events and the Event Flow……Page 559
On to Input Events……Page 563
Interactivity……Page 564
Flash Player’s Built-in Mouse Events……Page 565
Registering for Mouse Events……Page 570
Mouse Events and Overlapping Display Objects……Page 573
Finding the Mouse Pointer’s Position……Page 574
Handling Mouse Events “Globally”……Page 579
Focusing Objects with the Keyboard……Page 581
Handling descendant focus through a single ancestor……Page 583
Flash Player’s Focus Events……Page 584
Keyboard-Input Events……Page 588
Global Keyboard-Event Handling……Page 589
Object-Specific Keyboard-Event Handling……Page 590
Determining the Most Recently Pressed or Released Key……Page 591
Multilocation keys……Page 593
Detecting Multiple Simultaneous Key Presses……Page 594
Determining the Character Associated with a Key……Page 596
Text-Input Events……Page 598
The TextEvent.TEXT_INPUT and Event.CHANGE Events……Page 600
The Event.SCROLL Event……Page 604
The TextEvent.LINK Event……Page 610
Flash Player-Level Input Events……Page 613
The Event.ACTIVATE and Event.DEACTIVATE Events……Page 615
The Event.RESIZE Event……Page 616
The Event.MOUSE_LEAVE Event……Page 618
From the Program to the Screen……Page 619
Scheduled Screen Updates……Page 620
No Screen Updates Within Code Blocks……Page 626
Setting the Frame Rate……Page 627
Designated Frame Rate Versus Actual Frame Rate……Page 628
Post-Event Screen Updates……Page 629
Post-Event Updates for Timer Events……Page 631
Redraw Region……Page 633
Optimization with the Event.RENDER Event……Page 634
Let’s Make It Move!……Page 642
No Loops……Page 643
Animating with the ENTER_FRAME Event……Page 644
Frame Rate’s Effect on Event.ENTER_FRAME Animations……Page 648
Animating with the TimerEvent.TIMER Event……Page 649
Frame Rate’s Effect on Timer……Page 655
Choosing Between Timer and Event.ENTER_FRAME……Page 656
A Generalized Animator……Page 657
Velocity-Based Animation……Page 660
Moving On to Strokes ’n’ Fills……Page 661
Graphics Class Overview……Page 662
Drawing Lines……Page 663
Drawing Curves……Page 666
Drawing Shapes……Page 667
Removing Vector Content……Page 669
Example: An Object-Oriented Shape Library……Page 670
From Lines to Pixels……Page 680
Bitmap Programming……Page 681
Pixel Color Values……Page 682
Creating a New Bitmap Image……Page 687
Loading an External Bitmap Image……Page 689
Examining a Bitmap……Page 691
Transparency’s Effect on Color-Value Retrieval……Page 692
ColorPicker: A getPixel32() Example……Page 693
Retrieving the Color of a Region of Pixels……Page 695
Modifying a Bitmap……Page 697
Improve Performance with BitmapData.lock()……Page 698
ScribbleAS3: A setPixel32() Example……Page 699
Assigning the Color of a Region of Pixels……Page 701
Other Manipulation Tools……Page 703
Resizing a Bitmap……Page 704
The BitmapData Class’s Instance Method draw()……Page 705
The BitmapData Class’s Instance Method copyPixels()……Page 714
Applying Filters and Effects……Page 719
Applying Filters……Page 720
Freeing Memory Used by Bitmaps……Page 727
Words, Words, Words……Page 728
Text Display and Input……Page 729
Creating and Displaying Text……Page 732
Word Wrapping……Page 734
Automatic Resizing……Page 735
Modifying a Text Field’s Content……Page 738
Formatting Text Fields……Page 741
Formatting Text with the TextFormat Class……Page 742
Available TextFormat variables……Page 744
setTextFormat() does not apply to future text assignments……Page 746
Applying paragraph-level formatting……Page 747
Retrieving formatting information for a span of characters……Page 749
Default formatting for text fields……Page 750
Formatting Text with HTML……Page 752
Interactions between the text and htmlText variables……Page 757
Formatting Text with the StyleSheet Class……Page 759
Notable style sheet limitations in ActionScript……Page 762
Formatting text with a programmatically created style sheet……Page 763
Class selectors……Page 765
Formatting text with an externally loaded style sheet……Page 766
Fonts and Text Rendering……Page 768
Embedding Font Outlines in the Flash Authoring Tool……Page 770
Embedding Font Outlines in Flex Builder 2 and mxmlc……Page 771
Formatting Text with an Embedded Font……Page 774
Using bold and italic with embedded fonts……Page 776
Loading Fonts at Runtime……Page 778
Missing Fonts and Glyphs……Page 781
Determining Font Availability……Page 782
Determining Glyph Availability……Page 784
Embedded-Text Rendering……Page 785
Text Field Input……Page 788
Text Entry……Page 789
Formatting user input……Page 790
Text Selection……Page 791
Text Fields and the Flash Authoring Tool……Page 792
Loading…Please Wait………Page 794
Loading External Display Assets……Page 795
Creating the Loader Instance……Page 796
Specifying the Asset’s Location……Page 797
Starting the Load Operation……Page 799
Accessing the Loaded Asset……Page 800
Displaying the Loaded Asset On Screen……Page 803
Displaying Load Progress……Page 805
Why not use Event.OPEN?……Page 809
Handling Load Errors……Page 810
Environment-specific behavior for load failures……Page 812
Debugging with HTTPStatusEvent……Page 813
Compile-Time Type-Checking for Runtime-Loaded Assets……Page 814
Opting Out of Compile-Time Type-Checking……Page 816
Add the Module Class File to Main.swf’s source-path……Page 817
Add the Module Class File to Main.swf’s library-path……Page 818
Add the Module Class File to Main.swf’s external-library-path……Page 820
Accessing Assets in Multiframe .swf Files……Page 823
Instantiating a Loaded .swf File……Page 826
Instantiating a Loaded Image……Page 828
Server-Side: Sending the Asset……Page 829
Client-Side: Receiving the Asset……Page 833
Placing bytes in a buffer……Page 837
Creating a display asset from the loaded bytes……Page 838
Removing Runtime Loaded .swf Assets……Page 839
A Note on File Size and Memory Consumption……Page 840
General [Embed] Syntax……Page 841
Supported Asset Types……Page 842
Embedding Bitmap Images……Page 843
Embedding Entire .swf Files……Page 844
Embedding Symbols from Legacy .swf Files……Page 845
Embedding Files as Binary Data……Page 846
Using getDefinition() to Access a Class in an Embedded .swf File……Page 847
An [Embed] Example……Page 849
Clean the Project to See Changes……Page 850
On to Part III……Page 851
Part III Applied ActionScript Topics……Page 852
The Flash Document……Page 854
Timelines and Frames……Page 855
Keyframes and Regular Frames……Page 857
Timeline Scripting……Page 859
The Document Class……Page 861
Variable and Function Definitions in Frame Scripts……Page 864
Symbols and Instances……Page 865
Movie Clip Symbols……Page 866
Linked Classes for Movie Clip Symbols……Page 867
Accessing Manually Created Symbol Instances……Page 871
Instance Names……Page 872
Matching Variables for Instance Names……Page 874
Accessing Manually Created Text……Page 877
Programmatic Timeline Control……Page 878
Instantiating Flash Authoring Symbols via ActionScript……Page 880
Instance Names for Programmatically Created Display Objects……Page 881
Linking Multiple Symbols to a Single Superclass……Page 882
The Composition-Based Alternative to Linked Classes……Page 884
Preloading Classes……Page 885
Up Next: Using the Flex Framework……Page 888
The General Approach……Page 889
Create the Application Point of Entry……Page 890
Trigger the Application Point of Entry……Page 891
A Real UI Component Example……Page 892
Sharing with Your Friends……Page 893
Distributing a Class Library……Page 894
Sharing Class Source Files……Page 895
Creating a .swc-Based Class Library in Flex Builder 2……Page 896
Using a .swc-Based Class Library in Flex Builder 2……Page 897
Creating a .swc-Based Class Library in the Flash Authoring Tool……Page 898
Using a .swc-Based Class Library in the Flash Authoring Tool……Page 899
Distributing a Class Library as a .swf File……Page 900
Creating a .swf-Based Class Library in Flex Builder 2……Page 901
Using a .swf-Based Class Library in Flex Builder 2……Page 902
Creating a .swf-Based Class Library in the Flash Authoring Tool……Page 904
Using a .swf-Based Class Library in Flash CS3……Page 905
But Is It Really Over?……Page 906
The Final Virtual Zoo……Page 908
Index……Page 924
Reviews
There are no reviews yet.