Contents......Page 3 Overview of ActionScript Programming......Page 9 Contents......Page 11 Using this manual......Page 12 ActionScript 3.0 documentation......Page 13 Developer Center......Page 14 About ActionScript......Page 15 Core language features......Page 16 ECMAScript for XML (E4X)......Page 17 DOM3 event model......Page 18 Low-level data access......Page 19 Compatibility with previous versions......Page 20 The basic ActionScript development process......Page 23 Options for organizing your code......Page 24 Embedding code in Flex MXML files......Page 25 Designing your ActionScript application......Page 26 Creating the HelloWorld project and the Greeter class......Page 27 Creating a Flex application that uses your ActionScript code......Page 28 Enhancing the HelloWorld application......Page 30 Running subsequent examples......Page 34 Language overview......Page 35 Objects and classes......Page 37 Packages......Page 38 Importing packages......Page 40 Namespaces......Page 43 Defining namespaces......Page 44 Applying namespaces......Page 45 Using namespaces......Page 46 Variables......Page 50 Understanding variable scope......Page 52 Default values......Page 54 Data types......Page 55 Compile-time type checking......Page 56 Run-time type checking......Page 57 The is operator......Page 59 Dynamic classes......Page 60 Number data type......Page 62 Object data type......Page 64 Type conversions......Page 65 Explicit conversions......Page 66 Casting to int, uint, and Number......Page 67 Casting to Boolean......Page 69 Casting to String......Page 70 Dot syntax......Page 71 Literals......Page 72 Semicolons......Page 73 Comments......Page 74 Keywords and reserved words......Page 75 Constants......Page 76 Operators......Page 77 Operator precedence and associativity......Page 78 Primary operators......Page 80 Unary operators......Page 81 Additive operators......Page 82 Equality operators......Page 83 Assignment operators......Page 84 if..else......Page 85 if..else if......Page 86 switch......Page 87 for..in......Page 88 for each..in......Page 89 do..while......Page 90 Calling functions......Page 91 Function expressions......Page 92 Choosing between statements and expressions......Page 94 Returning values from functions......Page 96 Function parameters......Page 97 Passing arguments by value or by reference......Page 98 Default parameter values......Page 99 The arguments object......Page 100 The ... (rest) parameter......Page 102 Functions as objects......Page 103 The scope chain......Page 104 Function closures......Page 105 Contents......Page 107 Class definitions......Page 108 Class attributes......Page 109 Class body......Page 110 Access control namespace attributes......Page 111 static attribute......Page 113 Static variables......Page 114 Methods......Page 115 Constructor methods......Page 116 Static methods......Page 117 Instance methods......Page 118 Get and set accessor methods......Page 120 Bound methods......Page 121 Enumerations with classes......Page 122 Embedded asset classes......Page 125 Interfaces......Page 126 Defining an interface......Page 127 Implementing an interface in a class......Page 128 Inheritance......Page 129 Instance properties and inheritance......Page 131 Access control specifiers and inheritance......Page 132 Overriding variables not permitted......Page 133 The super statement......Page 134 Overriding getters and setters......Page 135 Static properties not inherited......Page 136 Static properties and the scope chain......Page 137 History of ActionScript OOP support......Page 138 ActionScript 1.0......Page 139 ActionScript 2.0......Page 141 The ActionScript 3.0 class object......Page 142 The prototype object......Page 143 The AS3 namespace......Page 145 Defining the GeometricShapes classes......Page 147 Defining the shape classes......Page 149 Polymorphism and the factory method......Page 153 Enhancing the example application......Page 155 Contents......Page 157 Understanding the display architecture......Page 158 Core display classes......Page 160 More efficient rendering and smaller file sizes......Page 162 Improved depth management......Page 163 Easier subclassing of display objects......Page 164 Properties and methods of the DisplayObject class......Page 165 Working with display object containers......Page 166 Traversing the display list......Page 170 Handling events for display objects......Page 172 Drawing vector graphics......Page 173 Working with text......Page 174 Loading content dynamically......Page 175 The LoaderInfo class......Page 176 The LoaderContext class......Page 178 Controlling ActionScript 3.0 movie clips......Page 179 Creating and manipulating bitmaps......Page 180 Working with SimpleButton objects......Page 181 Working with video......Page 182 Example: SpriteArranger......Page 183 The DrawingCanvas class......Page 184 Adding display objects to the canvas......Page 186 Clicking and dragging display objects......Page 188 Rearranging display object layering......Page 189 Core ActionScript 3.0 Data Types and Classes......Page 191 Creating Date objects......Page 193 Getting time unit values......Page 194 Doing date and time arithmetic......Page 195 Converting between time zones......Page 196 The Timer class......Page 197 Timing functions in the flash.utils package......Page 199 Defining the SimpleClock class......Page 200 Creating the clock face......Page 201 Displaying the current time......Page 202 Contents......Page 205 Declaring strings......Page 206 The length property......Page 207 Comparing strings......Page 208 Obtaining string representations of other objects......Page 209 Concatenating strings......Page 210 Finding a substring by character position......Page 211 Finding the character position of a matching substring......Page 212 Creating an array of substrings segmented by a delimiter......Page 213 Finding matching substrings......Page 214 Replacing matched substrings......Page 215 Example: ASCII Art......Page 217 Extracting tab-delimited values......Page 219 Using String methods to normalize image titles......Page 221 Generating the ASCII art text......Page 223 Contents......Page 225 Indexed arrays......Page 226 Inserting array elements......Page 227 Removing array elements......Page 228 Sorting an array......Page 230 Querying an array......Page 234 Extending the Array class......Page 235 Declaring the subclass......Page 236 TypedArray constructor......Page 237 TypedArray overridden methods......Page 238 Associative arrays with string keys......Page 240 Associative arrays with object keys......Page 242 Object keys and memory management......Page 243 Multidimensional arrays......Page 244 Two indexed arrays......Page 245 Associative array with an indexed array......Page 246 Cloning arrays......Page 247 PlayList class overview......Page 248 Adding a song to the list......Page 249 Properties for sorting......Page 250 Sorting by property and specifying sort options......Page 251 Combining array elements into a character-delimited string......Page 252 Contents......Page 253 Types of errors......Page 254 ActionScript 3.0 error handling improvements......Page 256 Working with the debugger version of Flash Player......Page 258 Using try..catch..finally statements......Page 259 The throw statement......Page 261 Displaying a simple error message......Page 262 Creating custom error classes......Page 263 Responding to error events and status......Page 265 Working with error events......Page 266 Working with status change events......Page 267 ECMAScript core Error classes......Page 269 ActionScript core Error classes......Page 272 flash.error package Error classes......Page 273 CustomErrors application overview......Page 275 Building a custom validator......Page 277 Defining the ApplicationError class......Page 278 Defining the FatalError class......Page 279 Defining the WarningError class......Page 280 Contents......Page 281 Introduction to regular expressions......Page 282 Creating an instance of a regular expression......Page 283 Characters, metacharacters, and metasequences......Page 284 About metacharacters......Page 285 About metasequences......Page 286 Escape sequences in character classes......Page 287 Ranges of characters in character classes......Page 288 Quantifiers......Page 289 Groups......Page 291 Using groups to capture substring matches......Page 292 Using noncapturing groups and lookahead groups......Page 293 Using named groups......Page 294 The g (global) flag......Page 295 The m (multiline) flag......Page 296 The x (extended) flag......Page 297 The source property......Page 298 The exec() method......Page 299 Example: A Wiki parser......Page 300 Defining the WikiParser class......Page 301 Converting bullet patterns......Page 302 Converting URLs to HTML tags......Page 303 Converting U.S. dollar strings to euro strings......Page 304 Contents......Page 307 A quick introduction to XML......Page 308 E4X: A new approach to XML processing......Page 309 XML objects......Page 311 XML methods......Page 312 XMLList objects......Page 314 Initializing XML variables......Page 315 Assembling and transforming XML objects......Page 316 Traversing XML structures......Page 318 Accessing parent and child nodes......Page 319 Accessing attributes......Page 320 Filtering by attribute or element value......Page 321 Using the for..in and the for each..in statements......Page 322 Using XML namespaces......Page 323 Converting XML and XMLList objects to strings......Page 324 Converting attribute values, names, and text values from strings......Page 325 Example: Loading RSS data from the Internet......Page 326 Reading and parsing XML data......Page 328 Assembling XMLList data......Page 329 Extracting the title of the RSS feed and sending a custom event......Page 330 Flash Player APIs......Page 331 Flash Player API Overview......Page 333 flash.display package......Page 334 flash.external package......Page 335 flash.net package......Page 336 flash.system package......Page 337 flash.xml package......Page 338 Contents......Page 339 Introduction to ActionScript event handling......Page 340 Event handling in previous versions of ActionScript......Page 341 Default behaviors......Page 342 What’s new for event listeners in ActionScript 3.0......Page 343 The event flow......Page 344 Event object types......Page 346 Event flow information......Page 347 Event class utility methods......Page 349 Event class default behavior methods......Page 350 Creating a listener function......Page 351 Listener function defined outside of a class......Page 352 Listener function defined as a class method......Page 353 Event listener that should not be used......Page 354 Managing event listeners......Page 355 Adding event listeners......Page 356 Checking for existing event listeners......Page 357 Example: Alarm Clock......Page 358 Alarm Clock overview......Page 359 Triggering the alarm......Page 360 Notifying others of the alarm......Page 362 Providing a custom alarm event......Page 363 Contents......Page 365 Using the URLLoader and URLVariables classes......Page 366 Loading data from external documents......Page 368 Communicating with external scripts......Page 372 LocalConnection class......Page 373 Sending messages between two Flash Player instances......Page 375 Connecting to SWF documents in different domains......Page 377 Socket class......Page 379 XMLSocket class......Page 380 Creating and connecting to a Java XML socket server......Page 382 Storing local data......Page 384 Displaying contents of a shared object......Page 386 Creating a secure SharedObject......Page 387 Working with file upload and download......Page 388 FileReference class......Page 389 Uploading files to a server......Page 391 Downloading files from a server......Page 396 FileReferenceList class......Page 397 Example: Building a Telnet client......Page 398 Telnet socket application overview......Page 399 Telnet class overview......Page 400 Displaying messages from the socket server......Page 401 Example: Uploading and downloading files......Page 402 FileIO application overview......Page 403 Downloading files from a remote server......Page 404 Initializing the FileDownload component......Page 405 Beginning the file download......Page 406 Cancelling a file download......Page 407 Initializing the FileUpload component......Page 408 Beginning a file upload......Page 409 Using Point objects......Page 411 Translating coordinate spaces......Page 412 Other uses of the Point class......Page 413 Resizing and repositioning Rectangle objects......Page 414 Finding unions and intersections of Rectangle objects......Page 416 Other uses of Rectangle objects......Page 417 Defining Matrix objects......Page 418 Defining a Matrix object for use with a gradient......Page 420 Example: Applying a matrix transformation to a display object......Page 422 The transform() method......Page 424 The scale() method......Page 425 Calling the MatrixTransformer.transform() method from the application......Page 426 System class......Page 427 Saving text to the Clipboard......Page 428 Capabilities class......Page 429 ApplicationDomain class......Page 430 IME class......Page 433 Determining which IME conversion mode is currently enabled......Page 434 Setting the IME conversion mode......Page 435 Disabling the IME for certain text fields......Page 436 Listening for IME composition events......Page 437 CapabilitiesExplorer overview......Page 438 CapabilitiesGrabber class overview......Page 439 Communicating with JavaScript......Page 440 Contents......Page 443 Security basics......Page 444 Administrative user controls......Page 446 The Global Flash Player Trust directory......Page 447 The Settings UI and Settings Manager......Page 448 The User Flash Player Trust directory......Page 449 Policy file syntax......Page 450 Socket policy files......Page 452 Preloading policy files......Page 453 Author (developer) controls......Page 454 Remote sandboxes......Page 455 Local sandboxes......Page 456 The Security.sandboxType property......Page 457 Loading SWF files and images......Page 458 Loading SWF files and images using the tag in a text field......Page 460 Cross-scripting......Page 461 Stage security......Page 463 Event security......Page 464 Accessing bitmap data......Page 465 Accessing sound data......Page 466 Accessing video data......Page 467 Connecting to sockets......Page 468 Uploading and downloading files......Page 470 Working with legacy content......Page 471 Setting LocalConnection permissions......Page 472 Controlling access to scripts in a host web page......Page 473 Shared objects......Page 474 Camera, microphone, Clipboard, mouse, and keyboard access......Page 476 Contents......Page 477 What’s new for the PrintJob class using ActionScript 3.0......Page 478 Flash Player tasks and system printing......Page 479 Working with exceptions and returns......Page 480 Working with page properties......Page 481 Timing print job statements......Page 482 Using rectangles for the print area......Page 483 Scaling......Page 484 Responding to page height and width......Page 485 Example: Multiple-page printing......Page 486 Example: Scaling, cropping, and responding......Page 488 Contents......Page 491 About the External API......Page 492 Using the ExternalInterface class......Page 493 Calling external code from ActionScript......Page 494 Calling ActionScript code from the container......Page 496 Example: Using the External API with a web page container......Page 497 Preparing for ActionScript-browser communication......Page 498 Exposing ActionScript methods to JavaScript......Page 501 Communication from ActionScript to the browser......Page 502 Calling ActionScript code from JavaScript......Page 503 Example: Using the External API with an ActiveX container......Page 505 Including the Shockwave Flash ActiveX control......Page 507 Understanding ActionScript to ActiveX container communication......Page 508 Inside the ExternalInterfaceProxy class......Page 511 The External API’s XML format......Page 513