Falls short of the Cookbook quality, outdated
14 May 2008 @ amazon.com
I’ve been a fan of programmer’s cookbooks ever since the famous Perl Cookbook ages ago. It’s a great way to get into a language and do away with any nagging thoughts that maybe you didn’t solve a problem well.
This specific cookbook falls short, though. I tried to read it cover to cover as well as individual chapters, but I found it oddly balanced. For example, the authors waste three recipes on about 10 pages about generating a random number (which is just one command!), and then describe event handling (the big thing!) on half a page. I also find it strange to read about trigonometry in a programmer’s book, and I don’t think recipes work very well for explaining basic language features (such as how to create a new object, or how to "trace a message").
Mostly though, the book is outdated with the release of flex2/3. Yes, Actionscript 3 is still current, but you don’t roll your own buttons as subclasses of sprite anymore!
In short, I give it three stars for content, and subtract 1 for being outdated. If you want to read about Actionscript 3, Adobe has a very nicely outlined pdf online, which is an easy read compared to these confusing and stale recipes.
A must-have book for those who want to get up to speed - fast!
25 Mar 2008 @ amazon.com
For those of us who have experience in many programming languages (C, C++, C#, JAVA etc.) who were introduced to flash and to actionscript (2.0/3.0) - I HIGHLY recommend this book as your first choice! - it’ll get you up to speed in a matter of a week or two!
I highly recommend taking some time aside and read it thoroughly. This is the best cookbook I’ve ever read. Very clear, well organized, easy to understand - you name it! In fact, I don’t know whether to consider it as a cookbook - as it is by all means an excellent learning textbook as well!!!
If you wanna be an actionscript 3.0 stud - start with this book.
A Useful Supplement
06 Mar 2008 @ amazon.com
This book is a is a supplement to other ActionScript books, and a big help to people who can do some things in Flex or Flash, and can maybe even write some ActionScript, but are not yet self-sufficient gurus. The ideas and information can be found in other sources, but it’s compiled here in a way that’s surprisingly handy. For example, there is a chapter on programmatic animation. It’s a good start, but for more detail, you really want Foundation Actionscript 3.0 Animation: Making Things Move!. Someone else already posted the table of contents, so no need to repeat it.
The book is a collection of code snippets with explanation text. The authors assume that readers are building projects and want to add some features or capabilities. The code snippets demonstrate how to implement these. It’s not exactly a beginner book, but it begins with ground-level concepts such as where to put ActionScript in a project, how to use mathematical operators, and how to trace messages. More complex topics follow.
I like the way information is presented. It provides a nice counterpoint to other ActionScript books I’ve been reading, with a "You want to do this. Here’s a way to do it" approach. I think this will be an excellent reference and I will use it a lot over the next several months. I can’t give it five stars because the web support for the book is lame compared to what I’ve seen for other texts. I understand authors are busy, but I think the online component is important for these ActionScript books. If you are an absolute beginner with ActionScript, I also recommend Learning ActionScript 3.0: A Beginner’s Guide. Thanks for reading.
Excellent for beginner/intermediate
29 Nov 2007 @ amazon.com
Excellent format: Q&A. Helps you find the syntax that you need and the solution for the most common problems you encounter programming AS3.
Anyway it’s not supposed to be complete and covering everything. I would recommend to a beginner/intermediate, specially to a previous AS2.0 developer like me. Cheers.
The title should be FLEX ActionScript 3.0
26 Sep 2007 @ amazon.com
I bought this book because I wanted to learn how to use AS3 over AS2. This book claims to be a ActionScript 3.0 which it is, but ONLY if you have the Flex Application.
I don’t have Adobe Flex but I would like to learn ActionScript 3.0 - this is too advanced for me and the applications aren’t what I thought they would be.
This book may be good for advanced users of ActionScript but for someone like me who was just getting used to ActionScript 2.0 and wants to learn how AS3 works- it’s the worst book you can buy.
As much as I like O’Reilly books, I feel this book is misleading.
Novice to Advanced users may think otherwise.
A Poor Sequel to Actionscript Cookbook
17 Sep 2007 @ amazon.com
Here’s an example of why this book deserves just one star (if that!):
Cre{2}l matches creel but not crel or creel
This example was taken from the section on regular expressions. There are other inaccuracies on that page. Overall, this book is riddled with inadequate, poor explanations that appear to typify the worse of IT personnel - bad communications skills. Anyone who gives this book high marks has not read the book entirely and is relying only on reputation.
Here’s another example:
var example:RegExp = /(\d)abc(\d*)/;
var result:Array = example.exec( "7abc" );
// Displays: 3
trace( result.length );
// Displays: 7abc
trace( result[0] );
// Displays: 7
trace( result[1] );
// Displays:
trace( result[2] );
Notice that the last display is missing. Really sloppy work. Not convinced? Try it at your own peril.
Skip this book.
Disappointing
13 Sep 2007 @ amazon.com
I have many O’Reilly books and I sorry to say this is my first diappointment. Many of the recipies are simply slight extensions of obvious constructs that are essentially just part of the Actionscipt language rather than interesting examples of how to put Actionscript to work or clever work-arounds as can be found in, for instance, the Perl Cookbook. To take one example, the multi-dimensional array recipe pretty much rehashes the Flash documentation - an array declared at ’compile time’ - rather than expanding on it and showing the less trivial example of, for instance, a dynamicaly declared array.
What is normally useful about the Cookbooks is that they are an excellent way to learn a new language for people who prefer to learn by example, deconstructing code rather than trawling through an enumeration of the elements of a language in a manual-type book. Most of the examples in this are sadly not complex enough to work this way - they’re too close to a one-concept-at-a-time manual - to show you how different elements of the language can acually work together to tackle full real-world programming tasks.
Great book on Actionscript...
05 Sep 2007 @ amazon.com
I’ve been learning Flex 2 and wanted to know a bit more about Actionscript and this book delivered! Plenty of good examples that have given me a MUCH better understanding of Actionscript. I never really learned much about Flash and so never wrote one line of Actionscript until I started to learn Flex (if you haven’t heard about Flex yet go to Adobe.com and read up about it, it’s pretty cool) and the books I had would show about 1/2 Actionscript and 1/2 mxml. So after getting a good understanding in mxml and basic Actionscript I wanted to learn more and this book was a big help. If you’re even remotely interested in learning Actionscript this is the book to get!
The end of a tunnel
04 Aug 2007 @ amazon.com
I consider myself as an early adopter of anything in interactive communication. I founded my company Falcomedia in 1989 with only one goal: to produce interactive multimedia communication. By then only possible on Mac’s with programs like Hypercard, Supercard (in color) or Macromind’s Director (called Videoworks by then). I definately see AS3 as the end of a tunnel and the start of really great things to come. It’s possible now, no workarounds, pure OOP and this book is basic.
Read als Keith Peter’s Actionsript 3.0 Animation and let your visions flow. I can’t see anything stopping us from bringing good UI, quality design, functionalty, efficient production and scalability to the next generation of the web.
Peter Bohny, Falcomedia Systems AG, Switzerland
Things you find out once you have bought this book
16 Jul 2007 @ amazon.co.uk
From page 1: ’This book assumes that you have obtained a copy of Flex Builder 2 and have succesfully installed it on your computer.’ Then it continues by using (just) Flex Builder.
This is an unpleasant surprise for the vast majority of ActionScript users used to Flash, not Flex Builder. Adobe sells Flex Builder 2 at $499. Flex Builder is a combination of the Flex SDK and Eclipse, both Open Source and free to download. This raises the question as to why Flex is so expensive. You’ll never find out from reading this book. Maybe we’ll have to buy another book from Lott, ’Programming Flex 2’, first?
Apart from this, there are too many ’dumb’ typo’s in this book - in contrast to the just two you’ll find in the online errata - something you wouldn’t expect from long-time serious publisher O’Reilly and an Adobe Developer Library book. Specially in computer code, every character counts, every developer is painfully aware.
The Missing Method();
28 Jun 2007 @ amazon.com
This book has what appears to be many great animation solutions; however, there is a very important piece missing. The code that connects the packages in the book to your time line in Flash CS3 Actionscript 3.0.
Tasty Recipes for Everyday Actionscript Use
17 Jun 2007 @ amazon.com
There is so much information packed into this book, it’s hard to sum it all up. Basically, if you have an actionscript question from TextFields to XML or loading video to gradient fills it will be answered in this book.
Probably the best part about this cookbook is how well organized it is. You’ll have no trouble finding the term you’re looking for in the table of contents or in the index if it’s something a little more specific. The answers fully answer the question without going on too many tangents. Sometimes it feels like they overexplain some of the examples because the example actionscript code can usually speak for itself.
I have a love/hate relationship with some of their answers because they choose to create a set of custom classes to solve some of the common problems. I appreciate how much time it saves to download their classes and then use their customs methods, but it almost feels like it’s cheating to teach that you’re supposed to use one of their custom classes to code correctly.
There seems to be some inconsistencies in the quality of the explanations as well. I imagine it’s because there are three different authors contributing to the book. Some of the examples are brilliant, while others seem barely adequate. For example, the sound chapter has excellent examples of adjusting volume, pan, and pulling sounds out of the sound spectrum (which is a very exciting addition to Actionscript 3!) which wraps up with a three page spread of code showing a full mp3 application with everything you might want to do with it. On the other hand, there’s the File Management chapter which seems choppy and mashed together and lacks a full package example showing a how all the code fits together.
Whatever way you look at it, there is a lot of value to this book. I know there’s code in the book that I will only use once or twice, but I’m glad to know that it’s there when the time comes to look it up. Although much of this information is available online, you will definitely save yourself hours of time by having this book handy on the shelf to pull out and quickly find the recipe you’re looking for. Although not perfect, I still feel like this book deserves 5 stars because it stands out above the rest of the Actionscript books out there.
Standard O’Reilly goodness
02 Jun 2007 @ amazon.com
This book is a great actionscript reference in the typical O’Reilly reference format.
Fast ramp up to Actionscript 3.0
11 Apr 2007 @ amazon.com
This book was exactly what I was looking for: a reference-style book to quickly look up how to do something specific with ActionScript 3. It is for generally experienced developers that already know what they want to do and just need to see how it’s done in with AS3 in the classic cookbook style.
There is no coverage of Flex or Flex Builder (perfect!). This is also not a tutorial book so you may need to look elsewhere if that is what you need.
Fast ramp up to Actionscript 3.0
11 Apr 2007 @ amazon.com
This book was exactly what I was looking for_ a reference-style book to quickly look up how to do something specific with ActionScript 3. It is for generally experienced developers that already know what they want to do and just need to see how it’s done in with AS3 in the classic cookbook style.
There is no coverage of Flex or Flex Builder (perfect!). This is also not a tutorial book so you may need to look elsewhere if that is what you need.
Sometimes great, but sometimes redundant and too wordy
03 Apr 2007 @ amazon.com
The authors for this book are all well-known, top-notch ActionScript developers and experienced authors. They’ve collected a nice set of tasks that are common enough that you are likely to want to know how to do them in ActionScript, but involved enough or cross-topic enough that you won’t be likely to find them in the in-product documentation.
The book also has a very nice supplemental code library. This is sort of a mixed blessing; it’s a download, so anyone can get it (not just people who pay for the book) and in several recipes the authors’ solution is just to "use class X and method Y from the book’s code library," without any explanation as to why the code works, or what it does under the covers. Depending on your coding style, you may or may not want that level of detail, but I’m the sort of person who does want it so it left me a little disappointed.
However, there’s also a lot in this book that doesn’t fit with my idea of what should be in the "cookbook" format book. In my mind, a "cookbook" is a book whose topics are more "edgy" or involved than what you might find in the core documentation. It should cover how to accomplish specific tasks that aren’t easily figured out and aren’t found elsewhere (again, especially not in the main documentation). It should also include "hacks" or workarounds to accomplishing things that aren’t readily available using the built-in functionality of the language.
This book has plenty of those topics, but it also has a lot of topics that are covered well and in sufficient detail in the in-product help. To make things worse, often those topics are not just given a one-page-or-less "cookbook" treatment (which would be useful for those "I know I’ve seen it before but I can’t quite remember what the syntax is" moments). Instead, they get the full four (or fourteen) page description, and you have to read through that description to extract the three lines of code that you actually need to put into your program.
In summary, I have mixed feelings about this book. When it’s good, it really shines--the sections that go into more depth or into a more advanced topic than Adobe’s ActionScript 3.0 documentation are really valuable. However, a significant part of the book is redundant with the documentation, doesn’t cover it in as much detail as the built-in documentation, but covers it in so much detail that the benefits of the "cookbook" format are lost.
A programmer’s companion!!
02 Apr 2007 @ amazon.com
With little introduction to ActionScript, I started reading this book. But couldn’t stop till I finished the entire book in few days. It makes a perfect companion for any ActionScript/Flex/Flash programmer. The book has plenty of useful codes, which covers a lot of depth & breadth.
I feel this is book 1 of 2
22 Mar 2007 @ amazon.com
A lot is covered, generally. Since ActionScript is at the heart of all Flash/Flex applications, I felt this book was in some areas premature and slim. In all fairness there’s a lot that can be covered, and I really felt like I’m waiting for an "Advanced Cookbook" to really sink my teeth into.
This book has both beginner and intermediate scenarios.
Great reference for all those frequently tasks...
19 Mar 2007 @ amazon.com
This is a great reference for all those finicky, frequently needed little tasks for which the syntax is so easy to forget, such as creating loaders, simulating dice/cards, sorting arrays, dealing with the display list, manipulating bitmaps, programming animation, XML etc.
An essential book for any Flex/Flash ActionScript3 programmer. I highly recommend this book.
Great reference for all those frequently needed tasks... a must have.
19 Mar 2007 @ amazon.com
This is a great reference for all those finicky, frequently needed tasks for which the syntax is so easy to forget, such as creating loaders, simulating dice/cards, dealing with the display list, manipulating bitmaps, programming animation, XML, etc.
An essential book for any Flex/Flash ActionScript3 programmer. I highly recommend this book.
Very nice! A must-have!
10 Mar 2007 @ amazon.com
As a developer w/ java background, I found this book nicely written and to the point! It clearly explains the major aspects of Action Script 3.0 w/ very useful, real-world examples throughout the book. I’ve been reading this book multiple times, each time finding something useful! Recommeded to any serious programmers!
Immediately Useful - A Great Read
15 Feb 2007 @ amazon.com
The "ActionScript 3.0 Cookbook" was a great read. In fact, I read most of it in a local bookstore in the course of one evening. The code samples were immediately useful and easy to follow - I have already put them to use in my current Flex 2 projects. Chapter 6 (Display List), Chapter 15 (Programming Sound), and Chapter 16 (Video) were especially useful to me. I found that looking up ActionScript-related keywords in the index allowed me to quickly get to the "good stuff" on a particular topic. For instance, I needed some help on adding a TextInput control to a Canvas using only ActionScript (e.g. not with the MXML tag). I found "adding item to display list, 141-145" in the index, and the detailed explanation of the solution was exactly what I needed - no fluff, just stuff. Thank you to O’Reilly and the authors, Joey Lott, Darron Schall, and Keith Peters for the inspiration.
Nice introduction and reference
07 Feb 2007 @ amazon.co.uk
This is a nice introduction which will help you to improve your understaning of ActionScript 3.0
You don’t need to read from beginning to end. Just browse through the topics and read the chapter that you are interested in.
It is explains how ActionScript 3.0 is different from 2.0 and examples are simple which makes reading through easy.
A Handy Reference for ActionScript Programmers
15 Jan 2007 @ amazon.com
Despite numerous typographical errors and several sections that reference outdated ActionScript 2 information, the ActionScript 3.0 Cookbook remains a very handy reference for developers who want quick, ready to implement solutions to common programming tasks and challenges.
This book is more of a desk reference for common tasks than an overall guide to the newest installment of Adobe’s ECMA-based programming language. The sections devoted to the new features of ActionScript 3 are very useful and have thorough explanations with well documented code samples. I found the chapter on the new model for adding visual elements to a SWF via ActionScript using the Display List to be particularly helpful in my study of AS3.’
To sum up my thoughts on the ActionScript 3.0 Cookbook: Definitely a worth the cover price for experienced ActionScript developers but maybe not the ideal resource for those developers that are just learning programming for the Flash Platform.
Its written well but its not intended for High level programing
09 Jan 2007 @ amazon.com
i don’t know why but i thought and hopped this book would take me to a world of things i couldn’t figure out on myself but unfortunately it didn’t.
its written very well and it its intended for a high level hello to actionScript 3.0 but sorry it was not enough for someone that is very deep into actionScript 2.0.
the importent new issues weren’t in focus.
Great book, full of simple solutions that inspire better development
20 Dec 2006 @ amazon.com
I checking this book at a local bookstore and decided to take it with me after reading some of the advanced recipes. This books not only covers Actionscript syntax but also best practices and concepts. The recipes are simple but can be applied to more complex real world problems.
As I said, the book is excellent but has a minor flaw. It seems that the source code was compiled using Flex 2 Beta 3. I am not going to list here the errata I have found; I already sent it to OReilly. But it is something to be aware of. Most of the stuff you can change yourself with the help of the compiler but it gets time consuming with the more complex examples.
Great book, full of simple solutions that inspire better development
20 Dec 2006 @ amazon.com
I was checking this book at a local bookstore and decided to take it with me after reading some of the advanced recipes. This book not only covers Actionscript syntax but also best practices and concepts. The recipes are simple but can be applied to more complex real world problems.
As I said, the book is excellent but has a minor flaw. It seems that the source code was compiled using Flex 2 Beta 3. I am not going to list the errata I found here; I already sent it to OReilly. But it is something to be aware of. Most of the stuff you can fix yourself with the help of the compiler but it gets time consuming with the more complex examples.
Solutions come from a leading consultant in the Flash arena
11 Dec 2006 @ amazon.com
If you’re using Adobe Flash or Flex software, you shouldn’t be without the program-specific ’recipes’ in the ActionScript 3.0 Cookbook. Here are the cross-referenced, quick look-up recipes for operating systems, formatting, accessibility, and options and alternates for strings. Solutions come from a leading consultant in the Flash arena, a Rich Internet Applications consultant, and a freelance Flash developer and pack in specific code suggestions and pros and cons of routines.
Diane C. Donovan
California Bookwatch
Excellent AS3 reference book!
04 Dec 2006 @ amazon.com
This book is by far the best programming book I have come across. Every topic is carefully grouped so that information on specific problems can be accessed quickly and easily.
One thing that I really like about this book is that you don’t have to read it from cover to cover. You could start in the middle with event-handling for example, then follow on to the next topic of your choice without feeling confused.
Another strong aspect of the book is its simplicity. It is VERY easy to understand and goes into great detail without overwhelming the reader.
This is just what I needed.
Another Joey Lott Masterpiece
17 Nov 2006 @ amazon.com
At the risk of sounding like a Joey Lott groupie, THIS BOOK IS EXCELLENT as is every book I’ve ever ready by Joey Lott. It is very concise, the examples are very understandable (if you have some AS 2.0 understanding to begin with) and in general exceedingly helpful. I will add that I wasn’t too impressed with the Flash 8 cookbook by Joey ( See, Joey isn’t perfect) but this cookbook is very worth buying.
ActionScript 3.0 Cookbook -- Excellent
17 Nov 2006 @ amazon.com
This is an excellent book. I’d recommend it to anyone using Flex 2 (and eventually Flash 9) -- especially now with the limited resources available for ActionScript 3 (AS3). There are a lot of useful examples along with coherent explanations of why the authors are programming the way they are.
The chapter on XML (chapter 20) is a must-read. It includes concise summaries of dealing with XML in AS3, which has changed significantly from AS2. Generally, XML handling is much easier in AS3, but there are some areas that can be really confusing when making the switch from AS2. This book explains most things you’ll need to do with XML in AS3.
The chapter titled "Display List" (chapter 6) also contains critical information for developers coming from AS2. The rendering model in Flash Player 9 is completely re-designed -- a move away from the MovieClip class (although it’s still in there) to the new DisplayObject class. The examples provided here give some important guidance on working with the various elements in rendering your project’s interface.
I particularly like some of the custom classes available as a free download (of course, you should buy the book for those!). For instance, recursive arrays can be a hassle to deal with, but very useful in many projects. One of the classes includes several Array utilities -- one, in particular, that makes dealing with recursive arrays easier.
Of course, there’s a lot of other great stuff in this book. I won’t touch on all its greatness, but, again, I do recommend it highly.
That said, I do have a few complaints.They are not to dissuade you from buying the book, but to give the authors some feedback, in hopes that they can improve the next edition.
The authors state that this book is not intended to be an introduction to AS3. However, since it’s really the first book to market on AS3, I’m sure that many AS3 developers will be looking to it for some introductory material.
The first 60 pages also seem to reinforce this impression. There are many pages devoted to basics of AS3, like creating functions and classes. Forcing these into the Cookbook scheme seems rather trite in several instances. Take, for instance, 2.5 Creating Subclasses. The Problem is stated as "You want to create a class that inherits from an existing class." And the Solution is "Write a subclass using the extends keyword." Now, if I know I want to create a class that inherits from another class, I’m pretty well along the way to knowing that I want to extend the latter. And I can probably find the answer much more readily in the Flex 2 or Flash 9 documentation. I’d rather see an appendix with documentation on the free-to-download custom classes, than 60 pages of very basic AS3.
In the interest of full disclosure, let me say that I have not read any of the Cookbook developer books lately, so some of my remarks may be a bit off base here. But it seems to me that this title falls short of the idea that I have for a Cookbook. There are a lot of good tidbits in here, like creating custom buttons and the inclusion of several custom class files, such as the already mentioned ArrayUtilities class (along with several other useful utilities classes) and the Cards class. But most of the Problems and Solutions are more like ingredients than recipes.
If I were editor of a book like this, I’d aim for more advanced Problems and Solutions that combine the various ingredients to provide a richer set of problems solved. How about solving the following Problems:
- I want to create a tile based game. How can I work with various sized grids to create a seamless experience for the user?
- I have tons of UI to place in the limits of the users’ screens. What are the various ways I can maximize the user experience (view stacks, tabs, and other new containers and navigator classes in AS3)?
- I want to program card games using the Cards class. How would I program a version of Blackjack?
- I need a reliable and reusable way to hit several web services. What’s a good way to split up my code into one or more classes to make this efficient?
Perhaps the Cookbook I’m describing better fits the Hacks series from O’Reilly. Or maybe it’s more of an Advanced Cookbook.
But, yes, it’s extremely useful. If you’re using Flex 2, or plan to use Flash 9, run out and buy a copy -- now!
FYI -- I’m the manager of the
Maine Flash Platform User Group. I’ve been using Flash since 1998. And I’m a recent convert to Flex 2.
Awesome Desktop Helper for a Professional Flash/FLEX 2 Developer
06 Nov 2006 @ amazon.com
You won’t be surprised with this book... it is up to par with the other resource rich Cookbooks we know and love from Oreilly.
NOTE: If you’re a Flash beginner, this is not the book for you. Check out "Object Oriented Actionscript for Flash 8" by Todd Yard and Peter Elst... then grab this book as your desk reference.
Nicely addresses the solutions to specific ActionScript task
05 Nov 2006 @ amazon.com
The book is focused on solution to a specfic problem and specfic task. Also the solutions covered are very well explained with good examples. This book is not a Actionscript Programming Guide. E4X support is very well explained.
A great addition to your ActionScript knowledge base
28 Oct 2006 @ amazon.com
The book is in the style of the classic O’Reilly Cookbook series format, in which each recipe presents the problem, the solution, and a discussion of the solution. You can quickly locate the recipe that most closely matches your situation and get the solution without having to read the whole book to understand the underlying code. The Discussion sections of each recipe offer a deeper analysis of how the solution works and possible design choices and ramifications. So you get the best of both worlds--quick and easy access to the answers you want and deeper insights into the nature of both the problem and the solution. The ActionScript 3.0 Cookbook helps you develop your understanding of concepts by applying them in real situations.
All of the code examples in this book are based on ActionScript 3.0 and only compatible work with products that support ActionScript 3.0. Flex 2.0 and Flash 9 allow you to author ActionScript 3.0 content. Flash Player 9 supports ActionScript 3.0. If you are using a product that does not support ActionScript 3.0, then the code in this book is not likely to work.
The following is the table of contents:
Chapter 1. ActionScript Basics
Recipe 1.1. Creating an ActionScript Project
Recipe 1.2. Customizing the Properties of an Application
Recipe 1.3. Where to Place ActionScript Code
Recipe 1.4. How to Trace a Message
Recipe 1.5. Handling Events
Recipe 1.6. Responding to Mouse and Key Events
Recipe 1.7. Using Mathematical Operators
Recipe 1.8. Checking Equality or Comparing Values
Recipe 1.9. Performing Actions Conditionally
Recipe 1.10. Performing Complex Conditional Testing
Recipe 1.11. Repeating an Operation Many Times
Recipe 1.12. Repeating a Task over Time
Recipe 1.13. Creating Reusable Code
Recipe 1.14. Generalizing a Method to Enhance Reusability
Recipe 1.15. Exiting a Method
Recipe 1.16. Obtaining the Result of a Method
Recipe 1.17. Handling Errors
Chapter 2. Custom Classes
Classes are absolutely essential to ActionScript 3.0. This is truer in ActionScript 3.0 than in any earlier release of the language. ActionScript 1.0 was essentially a procedural language with modest object-oriented features. ActionScript 2.0 formalized the object-oriented features and took a big step in the direction of a truly object-oriented language. However, ActionScript 3.0 shifts the core focus of ActionScript so that the basic building block is that of the class. If you are using ActionScript 3.0 with Flex, and the introduction of the minor exception of code being placed within mx_Script tags, all ActionScript code must appear within a class. This chapter discusses the fundamentals of writing custom classes in ActionScript 3.0.
Recipe 2.1. Creating a Custom Class
Recipe 2.2. Determining Where to Save a Class
Recipe 2.3. Creating Properties That Behave As Methods
Recipe 2.4. Creating Static Methods and Properties
Recipe 2.5. Creating Subclasses
Recipe 2.6. Implementing Subclass Versions of Superclass Methods
Recipe 2.7. Creating Constants
Recipe 2.8. Dispatching Events
Chapter 3. Runtime Environment
Flash Player 9 offers a relatively large amount of information about and control over the runtime environment. The flash.system.Capabilities class has many static methods that return information about the player and the computer on which it is running, such as the operating system, language, audio, and video capabilities. There are other classes such as flash.display.Stage and flash.system.Security that allow you to control other elements of the Player such as the right-click menu under Windows (Control-click on the Macintosh) and the Settings dialog box. The flash.display.Stage class also controls the scaling and alignment of the movie within the Player.
Recipe 3.1. Detecting the Player Version
Recipe 3.2. Detecting the Operating System
Recipe 3.3. Checking the Player Type
Recipe 3.4. Checking the System Language
Recipe 3.5. Detecting Display Settings
Recipe 3.6. Scaling the Movie
Recipe 3.7. Changing the Alignment
Recipe 3.8. Hiding the Flash Player’s Menu Items
Recipe 3.9. Detecting the Device’s Audio Capabilities
Recipe 3.10. Detecting the Device’s Video Capabilities
Recipe 3.11. Prompting the User to Change Player Settings
Recipe 3.12. Dealing with System Security
Chapter 4. Numbers and Math
Simple operations such as addition and subtraction are essential to even the most basic ActionScript applications, and more advanced math, such as random number generation and trigonometric calculations, is equally essential to advanced applications. ActionScript 3.0 has three basic numeric types: number, int, and uint. number is for any floating-point numbers, whereas int and uint are for integers (whole numbers). The distinction between int and uint is that int is the set of negative and non-negative integers, while uint is the set of non-negative integers (unsigned integers).
Recipe 4.1. Representing Numbers in Different Bases
Recipe 4.2. Converting Between Different Number Systems
Recipe 4.3. Rounding Numbers
Recipe 4.4. Inserting Leading or Trailing Zeros or Spaces
Recipe 4.5. Formatting Numbers for Display Without a Mask
Recipe 4.6. Formatting Currency Amounts
Recipe 4.7. Generating a Random Number
Recipe 4.8. Simulating a Coin Toss
Recipe 4.9. Simulating Dice
Recipe 4.10. Simulating Playing Cards
Recipe 4.11. Generating a Unique Number
Recipe 4.12. Converting Angle Measurements
Recipe 4.13. Calculating the Distance Between Two Points
Recipe 4.14. Determining Points Along a Circle
Recipe 4.15. Converting Between Units of Measurement
Chapter 5. Arrays
Recipe 5.1. Adding Elements to the Start or End of an Array
Recipe 5.2. Looping Through an Array
Recipe 5.3. Searching for Matching Elements in an Array
Recipe 5.4. Removing Elements
Recipe 5.5. Inserting Elements in the Middle of an Array
Recipe 5.6. Converting a String to an Array
Recipe 5.7. Converting an Array to a String
Recipe 5.8. Creating a Separate Copy of an Array
Recipe 5.9. Storing Complex or Multidimensional Data
Recipe 5.10. Sorting or Reversing an Array
Recipe 5.11. Implementing a Custom Sort
Recipe 5.12. Randomizing the Elements of an Array
Recipe 5.13. Getting the Minimum or Maximum Element
Recipe 5.14. Comparing Arrays
Recipe 5.15. Creating an Associative Array
Recipe 5.16. Reading Elements of an Associative Array
Chapter 6. Display List
The rendering model for ActionScript 3.0 and Flash Player 9 is radically different than in previous versions. The new renderer is still hierarchical, but not as rigid, and aims to simplify and optimize the rendering process. The new rendering model centers on the display list concept and focuses on the classes available in the flash.display package. The display list is a hierarchy that contains all visible objects in the .swf movie. Any object not on the display list is not drawn by the renderer. Each .swf movie contains exactly one display list, which is comprised of three types of elements: the stage, display object container, and display objects.
Recipe 6.1. Adding an Item to the Display List
Recipe 6.2. Removing an Item from the Display List
Recipe 6.3. Moving Objects Forward and Backward
Recipe 6.4. Creating Custom Visual Classes
Recipe 6.5. Creating Simple Buttons
Recipe 6.6. Loading External Images at Runtime
Recipe 6.7. Loading and Interacting with External Movies
Recipe 6.8. Creating Mouse Interactions
Recipe 6.9. Dragging and Dropping Objects with the Mouse
Chapter 7. Drawing and Masking
Recipe 7.1. Setting a Line Style
Recipe 7.2. Setting Gradient Line Styles
Recipe 7.3. Drawing a Line
Recipe 7.4. Drawing a Curve
Recipe 7.5. Drawing an Arc
Recipe 7.6. Drawing a Rectangle
Recipe 7.7. Drawing a Circle
Recipe 7.8. Drawing an Ellipse
Recipe 7.9. Drawing a Triangle
Recipe 7.10. Drawing Regular Polygons
Recipe 7.11. Drawing a Star
Recipe 7.12. Filling a Shape with a Solid or Translucent Color
Recipe 7.13. Filling a Shape with a Gradient
Recipe 7.14. Filling a Shape with a Bitmap
Recipe 7.15. Scripting Masks
Chapter 8. Bitmaps
Before Flash 8, support for bitmap images was minimal. Although they could be loaded and displayed, there wasn’t much you could do with them at runtime. The BitmapData class offers a nice set of tools for creating and manipulating bitmap graphics at runtime in Flash.
Recipe 8.1. Creating a BitmapData Object
Recipe 8.2. Adding a Bitmap to the Display List
Recipe 8.3. Drawing a Display Object to a Bitmap
Recipe 8.4. Loading an External Image into a Bitmap
Recipe 8.5. Manipulating Pixels
Recipe 8.6. Creating Rectangular Fills
Recipe 8.7. Creating a Flood Fill
Recipe 8.8. Copying Pixels
Recipe 8.9. Copying Channels
Recipe 8.10. Creating Noise
Recipe 8.11. Creating Perlin Noise
Recipe 8.12. Using Threshold
Recipe 8.13. Applying a Filter to a Bitmap
Recipe 8.14. Dissolving Between Two Bitmaps
Recipe 8.15. Scrolling a Bitmap
Chapter 9. Text
With ActionScript 3.0, the new text field object isn’t automatically added to the display list. That means that if you want to make the text field visible, you have to use the addChild( ) method. The addChild( ) method is defined for all container display objects, such as Sprite, and it adds the object specified as a parameter to the display list of the object from which it is called.
Recipe 9.1. Creating an Outline Around a Text Field
Recipe 9.2. Creating a Background for a Text Field
Recipe 9.3. Making a User Input Field
Recipe 9.4. Making a Password Input Field
Recipe 9.5. Filtering Text Input
Recipe 9.6. Setting a Field’s Maximum Length
Recipe 9.7. Displaying Text
Recipe 9.8. Displaying HTML-Formatted Text
Recipe 9.9. Condensing Whitespace
Recipe 9.10. Sizing Text Fields to Fit Contents
Recipe 9.11. Scrolling Text Programmatically
Recipe 9.12. Responding to Scroll Events
Recipe 9.13. Formatting Text
Recipe 9.14. Formatting User-Input Text
Recipe 9.15. Formatting a Portion of Existing Text
Recipe 9.16. Setting a Text Field’s Font
Recipe 9.17. Embedding Fonts
Recipe 9.18. Creating Text that Can Be Rotated
Recipe 9.19. Displaying Unicode Text
Recipe 9.20. Assigning Focus to a Text Field
Recipe 9.21. Selecting Text with ActionScript
Recipe 9.22. Setting the Insertion Point in a Text Field
Recipe 9.23. Responding When Text Is Selected or Deselected
Recipe 9.24. Responding to User Text Entry
Recipe 9.25. Adding a Hyperlink to Text
Recipe 9.26. Calling ActionScript from Hyperlinks
Recipe 9.27. Working with Advanced Text Layout
Recipe 9.28. Applying Advanced Anti-Aliasing
Recipe 9.29. Replacing Text
Recipe 9.30. Retrieving a List of System Fonts
Chapter 10. Filters and Transforms
ActionScript lets you to apply several different transforms and filters to display objects (and bitmaps) to change their color, shape, rotation, size, and to apply special effects. Transforms are changes in color, shape, rotation, and size. The remainder of special effects di scussed in this chapter use filters. Filters are native to Flash Player; they allow you to apply effects ranging from blurs to embossing.
Recipe 10.1. Applying Color Changes
Recipe 10.2. Applying Color Tints
Recipe 10.3. Resetting Color
Recipe 10.4. Shearing
Recipe 10.5. Applying Basic Filters
Recipe 10.6. Applying Advanced Filter Effects (Emboss, etc.)
Recipe 10.7. Embossing
Recipe 10.8. Detecting Edges
Recipe 10.9. Sharpening
Recipe 10.10. Making a Digital Negative
Recipe 10.11. Applying Grayscale
Recipe 10.12. Changing Saturation
Recipe 10.13. Changing Brightness
Recipe 10.14. Changing Contrast
Chapter 11. Programmatic Animation
In the earliest versions of Flash, most animation was done by using tweens. An object was placed on a keyframe, another keyframe was made, and the object was changed in some way. Flash filled in the frames in between, hence, the term tween. Using ActionScript, you can create much more dynamic and interactive animation.
Recipe 11.1. Moving an Object
Recipe 11.2. Moving an Object in a Specific Direction
Recipe 11.3. Easing
Recipe 11.4. Acceleration
Recipe 11.5. Springs
Recipe 11.6. Using Trigonometry
Recipe 11.7. Applying Animation Techniques to Other Properties
Chapter 12. Strings
Recipe 12.1. Joining Strings
Recipe 12.2. Using Quotes and Apostrophes in Strings
Recipe 12.3. Inserting Special Whitespace Characters
Recipe 12.4. Searching for a Substring
Recipe 12.5. Extracting a Substring
Recipe 12.6. Parsing a String into Words
Recipe 12.7. Removing and Replacing Characters and Words
Recipe 12.8. Retrieving One Character at a Time
Recipe 12.9. Converting Case
Recipe 12.10. Trimming Whitespace
Recipe 12.11. Reversing a String by Word or by Character
Recipe 12.12. Converting Between Strings and Unicode or ASCII
Chapter 13. Regular Expressions
One of the most powerful features added to ActionScript 3.0 is regular expressions. Regular expressions are, put simply, patterns that can be matched against strings. You may be familiar with other types of patterns, such as wildcards, which can be used to match patterns while searching for files. Patterns are also used in Recipe 9.5. Regular expressions support this type of pattern matching, but they are also much more sophisticated.
Recipe 13.1. Understanding Regular Expression Patterns
Recipe 13.2. Testing Regular Expressions
Recipe 13.3. Looking for Pattern Matches
Recipe 13.4. Removing and Replacing Characters and Words Using Patterns
Recipe 13.5. Creating a Nongreedy Pattern
Recipe 13.6. Validating User Input with Common Patterns
Chapter 14. Dates and Times
Recipe 14.1. Finding the Current Date and Time
Recipe 14.2. Retrieving the Date Values
Recipe 14.3. Retrieving the Day or Month Name
Recipe 14.4. Formatting the Date and Time
Recipe 14.5. Formatting Seconds or Milliseconds as Minutes and Seconds
Recipe 14.6. Converting Between DMYHMSM and Epoch Milliseconds
Recipe 14.7. Using Timers
Recipe 14.8. Calculating Elapsed Time or Intervals Between Dates
Recipe 14.9. Parsing a Date from a String
Chapter 15. Programming Sound
Recipe 15.1. Creating a Sound Object and Loading a Sound
Recipe 15.2. Starting and Stopping a Sound
Recipe 15.3. Setting the Buffer for a Sound
Recipe 15.4. Offsetting the Start of a Sound
Recipe 15.5. Playing a Sound Multiple Times (Looping)
Recipe 15.6. Getting the Size of a Sound File
Recipe 15.7. Reading the ID3 Tag of a Sound File
Recipe 15.8. Find Out When a Sound Finishes Playing
Recipe 15.9. Tracking the Progress of a Playing Sound
Recipe 15.10. Pausing and Restarting a Sound
Recipe 15.11. Reading the Level of a Sound
Recipe 15.12. Stopping All Sounds
Recipe 15.13. Reading the Sound Spectrum
Recipe 15.14. Changing the Volume or Pan of a Sound
Recipe 15.15. Creating a Sound Application
Chapter 16. Video
The Flash Player is capable of playing back video. Although it’s possible to embed video content within an .swf file, most Flash video content is stored in Flash video files (.flv files) and loaded into the Flash Player at runtime using ActionScript. By loading .flv files at runtime, you have smaller .swf files, more flexible content management, and greater control over the loading and playback of the video content.
Flash video loaded from .flv files has two faces: progressive download and streaming. Streaming .flv video requires a streaming server, such as Flash Media Server. In contrast, progressive download doesn’t require any additional software. However, for the most part, the ActionScript required to work with streaming and progressive download video is identical. The recipes in this chapter discuss how to work with progressive download video and focus exclusively on working with .flv files.
Recipe 16.1. Loading and Playing Back Video
Recipe 16.2. Controlling Video Sound
Recipe 16.3. Reading Playback Time
Recipe 16.4. Reading Video Duration
Recipe 16.5. Controlling Playback Time
Recipe 16.6. Scaling Video
Recipe 16.7. Managing and Monitoring Buffering and Loading
Recipe 16.8. Listening for Cue Points
Recipe 16.9. Applying Filters to Video
Recipe 16.10. Pausing and Resuming Video
Recipe 16.11. Stopping Video
Recipe 16.12. Scrubbing Video
Recipe 16.13. Clearing the Video Display
Recipe 16.14. Determining User Bandwidth
Chapter 17. Storing Persistent Data
This chapter focuses solely on local shared objects (LSOs). Local shared objects are similar to browser cookies in that they are stored on the client’s machine. LSOs are useful for storing the same kind of information for which cookies have traditionally been used, such as the ability for a web site to remember a user so that the user does not have to manually login during each visit. However, LSOs are more powerful than cookies because, by default, they never expire, they can store more data than cookies, they aren’t transmitted between the client and server, and they can store native ActionScript datatypes. In contrast to remote shared objects (RSOs), LSOs are available to use without any additional software involved on either the client or server.
Recipe 17.1. Creating and Opening a Local Shared Object
Recipe 17.2. Writing Data to a Shared Object
Recipe 17.3. Saving a Local Shared Object
Recipe 17.4. Reading Data from a Shared Object
Recipe 17.5. Removing Data from a Shared Object
Recipe 17.6. Serializing Custom Classes
Recipe 17.7. Sharing Data Between Flash Applications
Recipe 17.8. Controlling the Size of Local Shared Objects
Chapter 18. Communicating with Other Movies
Flash Player 6 introduced local connections, a means by which any Flash movie can broadcast to and listen for broadcasts from any other movie on the same computer. This chapter focuses on inter-movie communication through the use of LocalConnection, allowing multiple movies on the same client computer to interact with each other.
Recipe 18.1. Creating Local Connections
Recipe 18.2. Sending Data
Recipe 18.3. Validating Receipt of Communication over Local Connections
Recipe 18.4. Accepting Local Communications from Other Domains
Chapter 19. Sending and Loading Data
Sending and loading data has changed dramatically in ActionScript 3.0. The LoadVars class has been removed and replaced with a more robust URLLoader class in the flash.net package. URLLoader is supported by a new cast of characters, namely URLRequest, URLVariables, and URLStream (and a few others). These classes combine to form a rich API that offers more functionality and flexibility than what was available in previous versions.
Recipe 19.1. Loading Variables from a Text File
Recipe 19.2. Loading Variables from a Server-Side Script
Recipe 19.3. Loading a Block of Text (Including HTML and XML)
Recipe 19.4. Checking Load Progress
Recipe 19.5. Accessing Data Being Downloaded
Recipe 19.6. Sending Data to a Server-Side Script
Recipe 19.7. Sending Variables and Handling a Returned Result
Chapter 20. XML
ActionScript 3.0 boasts a revolutionary new syntax for working with XML. ECMAScript for XML, otherwise known as E4X, is a language extension that gives you a simpler, easier to read approach for working with XML objects than the traditional Document Object Model (DOM), an interface of the past. Using E4X, you’ll find that you can work with XML much easier than before. Additionally, if this is your first time working with XML, E4X dramatically lowers the learning curve of using XML.
Recipe 20.1. Understanding XML Structure (Reading and Writing XML)
Recipe 20.2. Creating an XML Object
Recipe 20.3. Adding Elements to an XML Object
Recipe 20.4. Adding Text Nodes to an XML Object
Recipe 20.5. Adding Attributes to an XML Element
Recipe 20.6. Reading Elements in an XML Tree
Recipe 20.7. Finding Elements by Name
Recipe 20.8. Reading Text Nodes and Their Values
Recipe 20.9. Reading an Element’s Attributes
Recipe 20.10. Removing Elements, Text Nodes, and Attributes
Recipe 20.11. Loading XML
Recipe 20.12. Loading XML from Different Domains
Recipe 20.13. Sending XML
Recipe 20.14. Searching XML
Recipe 20.15. Using HTML and Special Characters in XML
Chapter 21. Web Services and Flash Remoting
Flash Remoting and Web services both make asynchronous requests to service methods, and both can be used to create sophisticated client-server applications. The recipes in this chapter look at how to work with these technologies.
Recipe 21.1. Calling Web Services Methods
Recipe 21.2. Handling Web Services Responses
Recipe 21.3. Handling Web Services Errors
Recipe 21.4. Calling Flash Remoting Methods
Recipe 21.5. Handling Flash Remoting Responses
Chapter 22. Building Integrated Applications
The ExternalInterface class allows the Flash Player to communicate in a synchronous manner with the application within which it is embedded. In many cases that host application is a web browser. As such, this chapter focuses exclusively on how to build applications that integrate ActionScript and JavaScript when Flash Player is embedded in a browser
Recipe 22.1. Calling JavaScript Functions
Recipe 22.2. Calling ActionScript Functions
Recipe 22.3. Passing Parameters from HTML
Chapter 23. File Management
Prior to Version 8, the Flash Player did not support any mechanism for allowing the user to browse their computer for files. Furthermore, Flash Player didn’t have a mechanism for uploading or downloading files, either. As such, most web applications used HTML-based solutions for uploading and downloading files. Flash-based applications not deployed on the Web often had to use customized solutions for uploading and downloading files. Flash Player 8 and higher now supports the new APIs, which greatly simplify file I/O by allowing Flash Player to browse a user’s system for files to upload and download. Flash Player allows users to browse to files on their local disks and upload and download files using the FileReference and FileReferenceList classes. This chapter discusses the details of working with those APIs
Recipe 23.1. Downloading Files
Recipe 23.2. Detecting When a User Selects a File to Upload
Recipe 23.3. Monitoring Download Progress
Recipe 23.4. Browsing for Files
Recipe 23.5. Filtering Files That Display in the Browser Window
Recipe 23.6. Detecting When the User Has Selected a File to Upload
Recipe 23.7. Uploading Files
Recipe 23.8. Monitoring File Upload Progress
Chapter 24. Socket Programming
Socket connections allow the Flash Player to send and load data from a server over a specified network port. The main difference between socket and server connections in Chapter 20 is that socket connections don’t automatically close after data transfer is complete.
Binary socket connections are new in ActionScript 3.0 and enable raw connections that allow for transfer of binary information. Binary sockets are slightly more advanced than XML sockets because they require a low-level knowledge of binary datatypes, but they are also more powerful because you can connect to a wider range of socket servers and generally do more with them. For example, binary sockets allow you to connect to mail servers (via POP3, SMTP, and IMAP), news servers (via NNTP), chat servers, or even implement screen sharing and remote desktop applications by connection to a VNC server (via RFB). You’ll learn more about how to deal with the asynchronous nature of the Flash Players socket connections as you go through this chapter.
Recipe 24.1. Connecting to a Socket Server
Recipe 24.2. Sending Data
Recipe 24.3. Receiving Data
Recipe 24.4. Handshaking with a Socket Server
Recipe 24.5. Disconnecting from a Socket Server
Recipe 24.6. Handling Socket Errors
A great addition to your ActionScript knowledge base
28 Oct 2006 @ amazon.com
This book is in the style of the classic O’Reilly Cookbook series format, in which each recipe presents the problem, the solution, and a discussion of the solution. Each section pretty much stands alone, although you should understand chapter one on the basics before moving on. The Discussion sections of each recipe offer a good analysis of how the solution works and different design choices and their various ramifications. Thus you get the best of both worlds - quick and easy access to the answers you want and deeper insights into the nature of both the problem and the solution. The ActionScript 3.0 Cookbook helps you develop your understanding of concepts by applying them in real situations.
All of the code examples in this book are based on ActionScript 3.0 and only compatible with products that support ActionScript 3.0. Flex 2.0 and Flash 9 allow you to author ActionScript 3.0 content. Flash Player 9 supports ActionScript 3.0. If you are using a product that does not support ActionScript 3.0, then the code in this book is not likely to work.
The following is the table of contents:
Chapter 1. ActionScript Basics
Recipe 1.1. Creating an ActionScript Project
Recipe 1.2. Customizing the Properties of an Application
Recipe 1.3. Where to Place ActionScript Code
Recipe 1.4. How to Trace a Message
Recipe 1.5. Handling Events
Recipe 1.6. Responding to Mouse and Key Events
Recipe 1.7. Using Mathematical Operators
Recipe 1.8. Checking Equality or Comparing Values
Recipe 1.9. Performing Actions Conditionally
Recipe 1.10. Performing Complex Conditional Testing
Recipe 1.11. Repeating an Operation Many Times
Recipe 1.12. Repeating a Task over Time
Recipe 1.13. Creating Reusable Code
Recipe 1.14. Generalizing a Method to Enhance Reusability
Recipe 1.15. Exiting a Method
Recipe 1.16. Obtaining the Result of a Method
Recipe 1.17. Handling Errors
Chapter 2. Custom Classes
Classes are absolutely essential to ActionScript 3.0. This is truer in ActionScript 3.0 than in any earlier release of the language. ActionScript 1.0 was essentially a procedural language with modest object-oriented features. ActionScript 2.0 formalized the object-oriented features and took a big step in the direction of a truly object-oriented language. However, ActionScript 3.0 shifts the core focus of ActionScript so that the basic building block is that of the class. If you are using ActionScript 3.0 with Flex, and the introduction of the minor exception of code being placed within mx_Script tags, all ActionScript code must appear within a class. This chapter discusses the fundamentals of writing custom classes in ActionScript 3.0.
Recipe 2.1. Creating a Custom Class
Recipe 2.2. Determining Where to Save a Class
Recipe 2.3. Creating Properties That Behave As Methods
Recipe 2.4. Creating Static Methods and Properties
Recipe 2.5. Creating Subclasses
Recipe 2.6. Implementing Subclass Versions of Superclass Methods
Recipe 2.7. Creating Constants
Recipe 2.8. Dispatching Events
Chapter 3. Runtime Environment
Flash Player 9 offers a relatively large amount of information about and control over the runtime environment. The flash.system.Capabilities class has many static methods that return information about the player and the computer on which it is running, such as the operating system, language, audio, and video capabilities. There are other classes such as flash.display.Stage and flash.system.Security that allow you to control other elements of the Player such as the right-click menu under Windows (Control-click on the Macintosh) and the Settings dialog box. The flash.display.Stage class also controls the scaling and alignment of the movie within the Player.
Recipe 3.1. Detecting the Player Version
Recipe 3.2. Detecting the Operating System
Recipe 3.3. Checking the Player Type
Recipe 3.4. Checking the System Language
Recipe 3.5. Detecting Display Settings
Recipe 3.6. Scaling the Movie
Recipe 3.7. Changing the Alignment
Recipe 3.8. Hiding the Flash Player’s Menu Items
Recipe 3.9. Detecting the Device’s Audio Capabilities
Recipe 3.10. Detecting the Device’s Video Capabilities
Recipe 3.11. Prompting the User to Change Player Settings
Recipe 3.12. Dealing with System Security
Chapter 4. Numbers and Math
Simple operations such as addition and subtraction are essential to even the most basic ActionScript applications, and more advanced math, such as random number generation and trigonometric calculations, is equally essential to advanced applications. ActionScript 3.0 has three basic numeric types: number, int, and uint. number is for any floating-point numbers, whereas int and uint are for integers (whole numbers). The distinction between int and uint is that int is the set of negative and non-negative integers, while uint is the set of non-negative integers (unsigned integers).
Recipe 4.1. Representing Numbers in Different Bases
Recipe 4.2. Converting Between Different Number Systems
Recipe 4.3. Rounding Numbers
Recipe 4.4. Inserting Leading or Trailing Zeros or Spaces
Recipe 4.5. Formatting Numbers for Display Without a Mask
Recipe 4.6. Formatting Currency Amounts
Recipe 4.7. Generating a Random Number
Recipe 4.8. Simulating a Coin Toss
Recipe 4.9. Simulating Dice
Recipe 4.10. Simulating Playing Cards
Recipe 4.11. Generating a Unique Number
Recipe 4.12. Converting Angle Measurements
Recipe 4.13. Calculating the Distance Between Two Points
Recipe 4.14. Determining Points Along a Circle
Recipe 4.15. Converting Between Units of Measurement
Chapter 5. Arrays
Recipe 5.1. Adding Elements to the Start or End of an Array
Recipe 5.2. Looping Through an Array
Recipe 5.3. Searching for Matching Elements in an Array
Recipe 5.4. Removing Elements
Recipe 5.5. Inserting Elements in the Middle of an Array
Recipe 5.6. Converting a String to an Array
Recipe 5.7. Converting an Array to a String
Recipe 5.8. Creating a Separate Copy of an Array
Recipe 5.9. Storing Complex or Multidimensional Data
Recipe 5.10. Sorting or Reversing an Array
Recipe 5.11. Implementing a Custom Sort
Recipe 5.12. Randomizing the Elements of an Array
Recipe 5.13. Getting the Minimum or Maximum Element
Recipe 5.14. Comparing Arrays
Recipe 5.15. Creating an Associative Array
Recipe 5.16. Reading Elements of an Associative Array
Chapter 6. Display List
The rendering model for ActionScript 3.0 and Flash Player 9 is radically different than in previous versions. The new renderer is still hierarchical, but not as rigid, and aims to simplify and optimize the rendering process. The new rendering model centers on the display list concept and focuses on the classes available in the flash.display package. The display list is a hierarchy that contains all visible objects in the .swf movie. Any object not on the display list is not drawn by the renderer. Each .swf movie contains exactly one display list, which is comprised of three types of elements: the stage, display object container, and display objects.
Recipe 6.1. Adding an Item to the Display List
Recipe 6.2. Removing an Item from the Display List
Recipe 6.3. Moving Objects Forward and Backward
Recipe 6.4. Creating Custom Visual Classes
Recipe 6.5. Creating Simple Buttons
Recipe 6.6. Loading External Images at Runtime
Recipe 6.7. Loading and Interacting with External Movies
Recipe 6.8. Creating Mouse Interactions
Recipe 6.9. Dragging and Dropping Objects with the Mouse
Chapter 7. Drawing and Masking
Recipe 7.1. Setting a Line Style
Recipe 7.2. Setting Gradient Line Styles
Recipe 7.3. Drawing a Line
Recipe 7.4. Drawing a Curve
Recipe 7.5. Drawing an Arc
Recipe 7.6. Drawing a Rectangle
Recipe 7.7. Drawing a Circle
Recipe 7.8. Drawing an Ellipse
Recipe 7.9. Drawing a Triangle
Recipe 7.10. Drawing Regular Polygons
Recipe 7.11. Drawing a Star
Recipe 7.12. Filling a Shape with a Solid or Translucent Color
Recipe 7.13. Filling a Shape with a Gradient
Recipe 7.14. Filling a Shape with a Bitmap
Recipe 7.15. Scripting Masks
Chapter 8. Bitmaps
Before Flash 8, support for bitmap images was minimal. Although they could be loaded and displayed, there wasn’t much you could do with them at runtime. The BitmapData class offers a nice set of tools for creating and manipulating bitmap graphics at runtime in Flash.
Recipe 8.1. Creating a BitmapData Object
Recipe 8.2. Adding a Bitmap to the Display List
Recipe 8.3. Drawing a Display Object to a Bitmap
Recipe 8.4. Loading an External Image into a Bitmap
Recipe 8.5. Manipulating Pixels
Recipe 8.6. Creating Rectangular Fills
Recipe 8.7. Creating a Flood Fill
Recipe 8.8. Copying Pixels
Recipe 8.9. Copying Channels
Recipe 8.10. Creating Noise
Recipe 8.11. Creating Perlin Noise
Recipe 8.12. Using Threshold
Recipe 8.13. Applying a Filter to a Bitmap
Recipe 8.14. Dissolving Between Two Bitmaps
Recipe 8.15. Scrolling a Bitmap
Chapter 9. Text
With ActionScript 3.0, the new text field object isn’t automatically added to the display list. That means that if you want to make the text field visible, you have to use the addChild( ) method. The addChild( ) method is defined for all container display objects, such as Sprite, and it adds the object specified as a parameter to the display list of the object from which it is called.
Recipe 9.1. Creating an Outline Around a Text Field
Recipe 9.2. Creating a Background for a Text Field
Recipe 9.3. Making a User Input Field
Recipe 9.4. Making a Password Input Field
Recipe 9.5. Filtering Text Input
Recipe 9.6. Setting a Field’s Maximum Length
Recipe 9.7. Displaying Text
Recipe 9.8. Displaying HTML-Formatted Text
Recipe 9.9. Condensing Whitespace
Recipe 9.10. Sizing Text Fields to Fit Contents
Recipe 9.11. Scrolling Text Programmatically
Recipe 9.12. Responding to Scroll Events
Recipe 9.13. Formatting Text
Recipe 9.14. Formatting User-Input Text
Recipe 9.15. Formatting a Portion of Existing Text
Recipe 9.16. Setting a Text Field’s Font
Recipe 9.17. Embedding Fonts
Recipe 9.18. Creating Text that Can Be Rotated
Recipe 9.19. Displaying Unicode Text
Recipe 9.20. Assigning Focus to a Text Field
Recipe 9.21. Selecting Text with ActionScript
Recipe 9.22. Setting the Insertion Point in a Text Field
Recipe 9.23. Responding When Text Is Selected or Deselected
Recipe 9.24. Responding to User Text Entry
Recipe 9.25. Adding a Hyperlink to Text
Recipe 9.26. Calling ActionScript from Hyperlinks
Recipe 9.27. Working with Advanced Text Layout
Recipe 9.28. Applying Advanced Anti-Aliasing
Recipe 9.29. Replacing Text
Recipe 9.30. Retrieving a List of System Fonts
Chapter 10. Filters and Transforms
ActionScript lets you to apply several different transforms and filters to display objects (and bitmaps) to change their color, shape, rotation, size, and to apply special effects. Transforms are changes in color, shape, rotation, and size. The remainder of special effects di scussed in this chapter use filters. Filters are native to Flash Player; they allow you to apply effects ranging from blurs to embossing.
Recipe 10.1. Applying Color Changes
Recipe 10.2. Applying Color Tints
Recipe 10.3. Resetting Color
Recipe 10.4. Shearing
Recipe 10.5. Applying Basic Filters
Recipe 10.6. Applying Advanced Filter Effects (Emboss, etc.)
Recipe 10.7. Embossing
Recipe 10.8. Detecting Edges
Recipe 10.9. Sharpening
Recipe 10.10. Making a Digital Negative
Recipe 10.11. Applying Grayscale
Recipe 10.12. Changing Saturation
Recipe 10.13. Changing Brightness
Recipe 10.14. Changing Contrast
Chapter 11. Programmatic Animation
In the earliest versions of Flash, most animation was done by using tweens. An object was placed on a keyframe, another keyframe was made, and the object was changed in some way. Flash filled in the frames in between, hence, the term tween. Using ActionScript, you can create much more dynamic and interactive animation.
Recipe 11.1. Moving an Object
Recipe 11.2. Moving an Object in a Specific Direction
Recipe 11.3. Easing
Recipe 11.4. Acceleration
Recipe 11.5. Springs
Recipe 11.6. Using Trigonometry
Recipe 11.7. Applying Animation Techniques to Other Properties
Chapter 12. Strings
Recipe 12.1. Joining Strings
Recipe 12.2. Using Quotes and Apostrophes in Strings
Recipe 12.3. Inserting Special Whitespace Characters
Recipe 12.4. Searching for a Substring
Recipe 12.5. Extracting a Substring
Recipe 12.6. Parsing a String into Words
Recipe 12.7. Removing and Replacing Characters and Words
Recipe 12.8. Retrieving One Character at a Time
Recipe 12.9. Converting Case
Recipe 12.10. Trimming Whitespace
Recipe 12.11. Reversing a String by Word or by Character
Recipe 12.12. Converting Between Strings and Unicode or ASCII
Chapter 13. Regular Expressions
One of the most powerful features added to ActionScript 3.0 is regular expressions. Regular expressions are, put simply, patterns that can be matched against strings. You may be familiar with other types of patterns, such as wildcards, which can be used to match patterns while searching for files. Patterns are also used in Recipe 9.5. Regular expressions support this type of pattern matching, but they are also much more sophisticated.
Recipe 13.1. Understanding Regular Expression Patterns
Recipe 13.2. Testing Regular Expressions
Recipe 13.3. Looking for Pattern Matches
Recipe 13.4. Removing and Replacing Characters and Words Using Patterns
Recipe 13.5. Creating a Nongreedy Pattern
Recipe 13.6. Validating User Input with Common Patterns
Chapter 14. Dates and Times
Recipe 14.1. Finding the Current Date and Time
Recipe 14.2. Retrieving the Date Values
Recipe 14.3. Retrieving the Day or Month Name
Recipe 14.4. Formatting the Date and Time
Recipe 14.5. Formatting Seconds or Milliseconds as Minutes and Seconds
Recipe 14.6. Converting Between DMYHMSM and Epoch Milliseconds
Recipe 14.7. Using Timers
Recipe 14.8. Calculating Elapsed Time or Intervals Between Dates
Recipe 14.9. Parsing a Date from a String
Chapter 15. Programming Sound
Recipe 15.1. Creating a Sound Object and Loading a Sound
Recipe 15.2. Starting and Stopping a Sound
Recipe 15.3. Setting the Buffer for a Sound
Recipe 15.4. Offsetting the Start of a Sound
Recipe 15.5. Playing a Sound Multiple Times (Looping)
Recipe 15.6. Getting the Size of a Sound File
Recipe 15.7. Reading the ID3 Tag of a Sound File
Recipe 15.8. Find Out When a Sound Finishes Playing
Recipe 15.9. Tracking the Progress of a Playing Sound
Recipe 15.10. Pausing and Restarting a Sound
Recipe 15.11. Reading the Level of a Sound
Recipe 15.12. Stopping All Sounds
Recipe 15.13. Reading the Sound Spectrum
Recipe 15.14. Changing the Volume or Pan of a Sound
Recipe 15.15. Creating a Sound Application
Chapter 16. Video
The Flash Player is capable of playing back video. Although it’s possible to embed video content within an .swf file, most Flash video content is stored in Flash video files (.flv files) and loaded into the Flash Player at runtime using ActionScript. By loading .flv files at runtime, you have smaller .swf files, more flexible content management, and greater control over the loading and playback of the video content.
Flash video loaded from .flv files has two faces: progressive download and streaming. Streaming .flv video requires a streaming server, such as Flash Media Server. In contrast, progressive download doesn’t require any additional software. However, for the most part, the ActionScript required to work with streaming and progressive download video is identical. The recipes in this chapter discuss how to work with progressive download video and focus exclusively on working with .flv files.
Recipe 16.1. Loading and Playing Back Video
Recipe 16.2. Controlling Video Sound
Recipe 16.3. Reading Playback Time
Recipe 16.4. Reading Video Duration
Recipe 16.5. Controlling Playback Time
Recipe 16.6. Scaling Video
Recipe 16.7. Managing and Monitoring Buffering and Loading
Recipe 16.8. Listening for Cue Points
Recipe 16.9. Applying Filters to Video
Recipe 16.10. Pausing and Resuming Video
Recipe 16.11. Stopping Video
Recipe 16.12. Scrubbing Video
Recipe 16.13. Clearing the Video Display
Recipe 16.14. Determining User Bandwidth
Chapter 17. Storing Persistent Data
This chapter focuses solely on local shared objects (LSOs). Local shared objects are similar to browser cookies in that they are stored on the client’s machine. LSOs are useful for storing the same kind of information for which cookies have traditionally been used, such as the ability for a web site to remember a user so that the user does not have to manually login during each visit. However, LSOs are more powerful than cookies because, by default, they never expire, they can store more data than cookies, they aren’t transmitted between the client and server, and they can store native ActionScript datatypes. In contrast to remote shared objects (RSOs), LSOs are available to use without any additional software involved on either the client or server.
Recipe 17.1. Creating and Opening a Local Shared Object
Recipe 17.2. Writing Data to a Shared Object
Recipe 17.3. Saving a Local Shared Object
Recipe 17.4. Reading Data from a Shared Object
Recipe 17.5. Removing Data from a Shared Object
Recipe 17.6. Serializing Custom Classes
Recipe 17.7. Sharing Data Between Flash Applications
Recipe 17.8. Controlling the Size of Local Shared Objects
Chapter 18. Communicating with Other Movies
Flash Player 6 introduced local connections, a means by which any Flash movie can broadcast to and listen for broadcasts from any other movie on the same computer. This chapter focuses on inter-movie communication through the use of LocalConnection, allowing multiple movies on the same client computer to interact with each other.
Recipe 18.1. Creating Local Connections
Recipe 18.2. Sending Data
Recipe 18.3. Validating Receipt of Communication over Local Connections
Recipe 18.4. Accepting Local Communications from Other Domains
Chapter 19. Sending and Loading Data
Sending and loading data has changed dramatically in ActionScript 3.0. The LoadVars class has been removed and replaced with a more robust URLLoader class in the flash.net package. URLLoader is supported by a new cast of characters, namely URLRequest, URLVariables, and URLStream (and a few others). These classes combine to form a rich API that offers more functionality and flexibility than what was available in previous versions.
Recipe 19.1. Loading Variables from a Text File
Recipe 19.2. Loading Variables from a Server-Side Script
Recipe 19.3. Loading a Block of Text (Including HTML and XML)
Recipe 19.4. Checking Load Progress
Recipe 19.5. Accessing Data Being Downloaded
Recipe 19.6. Sending Data to a Server-Side Script
Recipe 19.7. Sending Variables and Handling a Returned Result
Chapter 20. XML
ActionScript 3.0 boasts a revolutionary new syntax for working with XML. ECMAScript for XML, otherwise known as E4X, is a language extension that gives you a simpler, easier to read approach for working with XML objects than the traditional Document Object Model (DOM), an interface of the past. Using E4X, you’ll find that you can work with XML much easier than before. Additionally, if this is your first time working with XML, E4X dramatically lowers the learning curve of using XML.
Recipe 20.1. Understanding XML Structure (Reading and Writing XML)
Recipe 20.2. Creating an XML Object
Recipe 20.3. Adding Elements to an XML Object
Recipe 20.4. Adding Text Nodes to an XML Object
Recipe 20.5. Adding Attributes to an XML Element
Recipe 20.6. Reading Elements in an XML Tree
Recipe 20.7. Finding Elements by Name
Recipe 20.8. Reading Text Nodes and Their Values
Recipe 20.9. Reading an Element’s Attributes
Recipe 20.10. Removing Elements, Text Nodes, and Attributes
Recipe 20.11. Loading XML
Recipe 20.12. Loading XML from Different Domains
Recipe 20.13. Sending XML
Recipe 20.14. Searching XML
Recipe 20.15. Using HTML and Special Characters in XML
Chapter 21. Web Services and Flash Remoting
Flash Remoting and Web services both make asynchronous requests to service methods, and both can be used to create sophisticated client-server applications. The recipes in this chapter look at how to work with these technologies.
Recipe 21.1. Calling Web Services Methods
Recipe 21.2. Handling Web Services Responses
Recipe 21.3. Handling Web Services Errors
Recipe 21.4. Calling Flash Remoting Methods
Recipe 21.5. Handling Flash Remoting Responses
Chapter 22. Building Integrated Applications
The ExternalInterface class allows the Flash Player to communicate in a synchronous manner with the application within which it is embedded. In many cases that host application is a web browser. As such, this chapter focuses exclusively on how to build applications that integrate ActionScript and JavaScript when Flash Player is embedded in a browser
Recipe 22.1. Calling JavaScript Functions
Recipe 22.2. Calling ActionScript Functions
Recipe 22.3. Passing Parameters from HTML
Chapter 23. File Management
Prior to Version 8, the Flash Player did not support any mechanism for allowing the user to browse their computer for files. Furthermore, Flash Player didn’t have a mechanism for uploading or downloading files, either. As such, most web applications used HTML-based solutions for uploading and downloading files. Flash-based applications not deployed on the Web often had to use customized solutions for uploading and downloading files. Flash Player 8 and higher now supports the new APIs, which greatly simplify file I/O by allowing Flash Player to browse a user’s system for files to upload and download. Flash Player allows users to browse to files on their local disks and upload and download files using the FileReference and FileReferenceList classes. This chapter discusses the details of working with those APIs
Recipe 23.1. Downloading Files
Recipe 23.2. Detecting When a User Selects a File to Upload
Recipe 23.3. Monitoring Download Progress
Recipe 23.4. Browsing for Files
Recipe 23.5. Filtering Files That Display in the Browser Window
Recipe 23.6. Detecting When the User Has Selected a File to Upload
Recipe 23.7. Uploading Files
Recipe 23.8. Monitoring File Upload Progress
Chapter 24. Socket Programming
Socket connections allow the Flash Player to send and load data from a server over a specified network port. The main difference between socket and server connections in Chapter 20 is that socket connections don’t automatically close after data transfer is complete.
Binary socket connections are new in ActionScript 3.0 and enable raw connections that allow for transfer of binary information. Binary sockets are slightly more advanced than XML sockets because they require a low-level knowledge of binary datatypes, but they are also more powerful because you can connect to a wider range of socket servers and generally do more with them. For example, binary sockets allow you to connect to mail servers (via POP3, SMTP, and IMAP), news servers (via NNTP), chat servers, or even implement screen sharing and remote desktop applications by connection to a VNC server (via RFB). You’ll learn more about how to deal with the asynchronous nature of the Flash Players socket connections as you go through this chapter.
Recipe 24.1. Connecting to a Socket Server
Recipe 24.2. Sending Data
Recipe 24.3. Receiving Data
Recipe 24.4. Handshaking with a Socket Server
Recipe 24.5. Disconnecting from a Socket Server
Recipe 24.6. Handling Socket Errors