March 30, 2007

Chapter 12, Paragraphs 1-10, Essential ActionScript 3.0

Here are the first 10 paragraphs of Chapter 12 of Essential ActionScript 3.0

12. Events and Event Handling

In general terms, an event is a noteworthy runtime occurrence that has the potential to trigger a response in a program. In ActionScript, events can be broken into two categories: built-in events, which describe changes to the state of the runtime environment; and custom events, which describe changes to the state of a program. For example, a built-in event might be the clicking of the mouse or the completion of a file-load operation. By contrast, a custom event might be the ending of a game or the submission of an answer in a quiz.

Events are ubiquitous in ActionScript. In fact, in a pure ActionScript program, once the main-class constructor method has finished executing, all subsequent code is triggered by events. Accordingly, ActionScript supports a rich event architecture that provides the foundation for both built-in and custom events.

ActionScript’s event architecture is based on the W3C Document Object Model (DOM) Level 3 Events Specification, available at http://www.w3.org/TR/DOM-Level-3-Events.

This chapter teaches the fundamentals of ActionScript’s event architecture, covering both how to respond to built-in events and how to implement custom events in an ActionScript program. Note, however, that this chapter covers event fundamentals only. Later, in Chapter 21, Events and Display Hierarchies, we’ll study how ActionScript’s event architecture caters to display objects (objects that represent on-screen content). Then, in Chapter 22, Interactivity, we’ll examine a variety of specific built-in user-input events.

ActionScript Event Basics

In order to handle (respond to) events in an ActionScript program, we use event listeners. An event listener is a function or method that registers to be executed when a given event occurs. Event listeners are so named because they conceptually wait (listening) for events to happen. To notify a program that a given event has occurred, ActionScript executes any and all event listeners that have registered for that event. The notification process is known as an event dispatch.

When a given event dispatch is about to begin, ActionScript creates an object—known as the event object—that represents the event. The event object is always an instance of the Event class, or one of its descendants. All event listeners executed during the event dispatch are passed a reference to the event object as an argument. Each listener can use the event object’s variables to access information relating to the event. For example, a listener for an event representing mouse activity might use the variables of the event object to determine the location of the mouse pointer at the time of the event.

Every type of event in ActionScript—whether built-in or custom—is given a string name. For example, the name of the “mouse click” event-type is “click”. During an event dispatch, the name of the event being dispatched can be retrieved via the 'type' variable of the event object passed to every listener.

Each event dispatch in ActionScript has an event target, which is the object to which the event conceptually pertains. For example, for input events, the event target is typically the object that was manipulated (clicked on, typed into, moved over, etc.). Likewise, for network events, the event target is typically the object that instigated the network operation.

To respond to a given event, listeners typically register with the event target. Accordingly, all event target objects are instances of a class that inherits from the EventDispatcher class, or that implements the IEventDispatcher interface. The EventDispatcher class provides methods for registering and unregistering event listeners (addEventListener() and removeEventListener(), respectively).
In Chapter 21, we’ll learn that when the event target is a display object (an object that can be displayed on screen), event listeners can also register with the event target’s display ancestors (i.e., objects that visually contain the event target). For now, however, we’ll concentrate solely on non-displayable event-target objects.

Posted by moock at 07:20 PM

March 29, 2007

Chapter 11, Paragraphs 1-5, Essential ActionScript 3.0

Here are the first 5 paragraphs of Chapter 11 of Essential ActionScript 3.0

11. Arrays

Arrays are used to store and manipulate ordered lists of information and are, therefore, a fundamental tool in sequential, repetitive programming. We use arrays to do everything from storing user input, to generating pull-down menus, to keeping track of enemy spacecraft in a game. Practically speaking, an array is just a list of items, like your grocery list or the entries in your checkbook ledger. The items just happen to be ActionScript values.

What Is an Array?

An array is a data structure that can encompass multiple individual data values in an ordered list. Here is a simple example showing two separate strings, followed by an array that contains two strings:

"cherries" // A single string
"peaches" // Another string
["oranges", "apples"] // A single array containing two strings

An array can contain any number of items, including items of different types. An array can even contain other arrays. Here is a simple example showing an array that contains both strings and numbers. It might represent your shopping list, showing how many of each item you intend to buy:

["oranges", 6, "apples", 4, "bananas", 3];

Though an array can keep track of many values, it’s important to recognize that the array itself is a single data value. Arrays are represented as instances of the Array class. As such, an array can be assigned to a variable or used as part of a complex expression:

// Assign an array to a variable
var product:Array = ["ladies downhill skis", 475];

// Pass that array to a function
display(product);

Each item in an array is called an array element, and each element has a unique numeric position (index) by which we can refer to it.

Posted by moock at 07:39 PM

March 28, 2007

Chapter 10, Paragraphs 1-3, Essential ActionScript 3.0

Here are the first 3 paragraphs of Chapter 10 of Essential ActionScript 3.0

10. Statements and Operators

This chapter provides a reference-style overview of ActionScript’s statements and operators—many of which we’ve already seen in this book. Rather than discussing each statement and operator in isolation, this book teaches the use of statements and operators in the context of other programming topics. Accordingly, this chapter lists many cross-references to discussion and usage examples found elsewhere in this book. For information on operators not covered in this book, see Adobe’s ActionScript Language Reference.

Statements are one kind of directive, or basic program instruction, consisting of a keyword (command name reserved for use by the ActionScript language) and, typically, a supporting expression.

Table 10-1 lists ActionScript’s statements, their syntax, and purpose.

Posted by moock at 07:45 PM

March 27, 2007

support your favourite site when ordering cs3 software

if you're planning on buying adobe software, remember to help out your favourite flash site by placing your order through its affiliate link, if it has one. when you order through an affiliate link, the site owner gets a cut of the sale (2-8%).

cash earned via an affiliate link can help pay for ISP bills, time, and other expenses. if you belong to a software user group, be sure to check your group's site to see if it has an affiliate link. if it doesn't, contact the group manager and ask for one to be added. after all, if you're buying the software anyway, you might as well help support your dev community.

here are moock.org's affiliate links:

* Creative Suite 3 Master Collection
* Creative Suite 3 Production Premium
* Creative Suite 3 Design Premium
* Creative Suite 3 Design Standard
* Creative Suite 3 Web Premium
* Creative Suite 3 Web Standard

* Flex Builder 2
* Flash CS3
* Dreamweaver CS3
* Photoshop CS3
* Photoshop CS3 Extended
* Fireworks CS3
* Illustrator CS3
* Contribute CS3
* InDesign CS3
* Premiere Pro CS3
* Soundbooth CS3
* After Effects CS3

Posted by moock at 08:16 PM

Chapter 9, Paragraphs 1-3, Essential ActionScript 3.0

Here are the first 3 paragraphs of Chapter 9 of Essential ActionScript 3.0

9. Interfaces

An interface is an ActionScript language construct used to define a new datatype, much as a class defines a datatype. However, whereas a class both defines a datatype and provides the implementation for it, an interface defines a datatype in abstract terms only, and provides no implementation for that datatype. That is, a class doesn’t just declare a bunch of methods and variables, it also supplies concrete behavior—the method bodies and variable values that make the class actually do something. An interface, instead of providing its own implementation, is adopted by one or more classes that agree to provide the implementation. Instances of a class that provides an implementation for an interface belong both to the class’s datatype and to the datatype defined by the interface. As a member of multiple datatypes, the instances can then play multiple roles in an application.

Don’t confuse the term interface, as discussed in this chapter, with other uses of the word. In this chapter, “interface” refers to an ActionScript language construct, not a graphical user interface (GUI) or the public API of a class, sometimes also called an interface in general object-oriented programming theory.

Unless you’re familiar with interfaces already, theoretical descriptions of them can be hard to follow, so let’s dive right into an example.

Posted by moock at 07:52 PM

March 26, 2007

Chapter 8, Paragraphs 1-8, Essential ActionScript 3.0

Here are the first 8 paragraphs of Chapter 8 of Essential ActionScript 3.0

8. Datatypes and Type Checking

So far, we’ve developed our virtual zoo program without making a single coding error. Error-free development happens in training courses and books—and nowhere else. In real-world development, programmers make errors all the time. For example, when invoking eat() on a VirtualPet object, a programmer might make a typographical error, such as the following (notice the extra “t”):

pet.eatt(new Sushi())

Or, a programmer might make a mistaken assumption about the capabilities of an object. For example, a programmer might mistakenly attempt to invoke a method named jump() on a VirtualPet object, even though VirtualPet defines no such method:

pet.jump()

In both of the preceding cases, when the program runs in the debugger version of a Flash runtime, ActionScript will generate a reference error, indicating that the program attempted to reference a variable or method that doesn’t exist.

Errors that occur at runtime are known as "exceptions." We’ll study exceptions and the techniques for handling them in Chapter 13.

When an error occurs in a program you’re writing, you should be happy. Errors indicate the precise location and cause of something in your program that would likely cause a malfunction without your attention. For example, in response to the earlier “eatt()” typo, the debugger version of a Flash runtime would display an alert dialog containing the following message:

ReferenceError: Error #1069: Property eatt not found on
zoo.VirtualPet and there is no default value.
at VirtualZoo$iinit()[C:\data\virtualzoo\src\VirtualZoo.as:8]

The error message tells us not only the name of the file in which the error occurred, but also the specific line of code containing the error. Now that’s service. (Notice that the error message uses the term property to mean “variable or method,” as discussed in Chapter 1 under “Members and Properties.”)

As useful as runtime errors are, they have a potential drawback. They occur only when the erroneous line of code actually runs. Therefore, in a very large program, a runtime error might take a long time to surface. For example, in an adventure game that takes 10 hours to complete, an error in the final stage would take 10 hours of game-play to surface!

Luckily, rather than waiting for reference errors to occur at runtime, we can tell the compiler to report them at compile-time, before a program ever runs. To do so, we use type annotations in combination with strict mode compilation.

Posted by moock at 07:49 PM

March 23, 2007

Chapter 7, Paragraph 1, Essential ActionScript 3.0

Here is the first paragraph of Chapter 7 of Essential ActionScript 3.0

7. Compiling and Running a Program

After all our hard work on the virtual zoo program, we are now ready to compile and run our code. In this chapter, we’ll learn how to compile a program with the Flash authoring tool, Flex Builder 2, and mxmlc. In each case, we’ll assume that the program being compiled resides in the folder /virtualzoo/, and that the source code for the program (i.e., the .as files) resides in the folder /virtualzoo/src/.

Now let’s do some compiling!

Posted by moock at 05:32 PM

March 22, 2007

Chapter 6, Paragraphs 1-3, Essential ActionScript 3.0

Here are the first 3 paragraphs of Chapter 6 of Essential ActionScript 3.0

6. Inheritance

In object-oriented programming, inheritance is a formal relationship between two or more classes, wherein one class borrows (or inherits) the variable and method definitions of another class. In the practical, technical sense, inheritance simply lets one class make use of the code in another class.

But the term inheritance implies much more than code reuse. Inheritance is as much an intellectual tool as it is a technical tool. It lets programmers conceptualize a group of classes in hierarchical terms. In biology, inheritance is a genetic process through which one living creature passes on traits to another. You are said to have inherited your mother’s eyes or your father’s nose, even though you don’t look exactly like either of your parents. In object-oriented programming, inheritance has a similar connotation. It lets a class look and feel in many ways like another class, while adding its own unique features.

This chapter begins by examining the syntax and general use of inheritance. Once we understand inheritance on a practical level, we’ll consider its benefits and alternatives. Finally, we’ll apply inheritance to our virtual zoo program.

Posted by moock at 07:03 PM

March 21, 2007

mike downey's ebay apollo demo

with the recent release of adobe's apollo on adobe labs, there's a lot of new info to digest. ignoring the many technical details, my personal favourite high-level overview of apollo is mike downey's ebay demo. at only 6 minutes long, it's well worth a watch.

>> view mike's apollo demo

Posted by moock at 09:56 PM

Chapter 5, Paragraphs 1&2, Essential ActionScript 3.0

Here are the first 2 paragraphs of Chapter 5 of Essential ActionScript 3.0

5. Functions

A function, or more specifically a function closure, is a discrete set of instructions that carry out some task, independent of any class or object. Functions closures have the same basic syntax and usage as instance methods and static methods—they are defined with the function keyword, can define local variables, are invoked with the parentheses operator, and can optionally return a value. However, unlike instance methods (which are always associated with an object) and static methods (which are always associated with a class), function closures are created and used in standalone form, either as a subtask in a method, or a general utility available throughout a package or an entire program.

In the strict technical jargon of the ActionScript 3.0 specification, function closures and methods are both considered types of functions, where the term function refers generally to a callable object representing a set of instructions. Thus, a function closure is a function that is not associated with an object or a class, while a method is a function that is associated with an object (in the case of instance methods) or a class (in the case of static methods). However, in common discussion and most documentation, the term function closure is shortened to function. Unless you are reading the ActionScript 3.0 specification or a text that specifically states otherwise, you can safely assume that function means function closure. In the remainder of this book, the term function means function closure, except where stated otherwise.

Posted by moock at 05:59 PM

March 20, 2007

Chapter 4, Paragraphs 1&2, Essential ActionScript 3.0

Here are the first 2 paragraphs of Chapter 4 of Essential ActionScript 3.0

4. Static Variables and Static Methods

In Chapter 1, we learned how to define the characteristics and behavior of an object using instance variables and instance methods. In this chapter, we’ll learn how to manage information and create functionality that pertains to a class, itself, rather than its instances.

Static Variables

Over the past several chapters, we’ve had a fair bit of practice working with instance variables, which are variables associated with a particular instance of a class. Static variables, by contrast, are variables associated with a class itself, rather than a particular instance of that class. Static variables are used to keep track of information that relates logically to an entire class, as opposed to information that varies from instance to instance. For example, a class representing a dialog box might use a static variable to specify the default size for new dialog box instances, or a class representing a car in a racing game might use a static variable to specify the maximum speed of all car instances.

Posted by moock at 09:14 PM

March 16, 2007

Chapter 3, Paragraphs 1&2, Essential ActionScript 3.0

Here are the first two paragraphs of Chapter 3 of Essential ActionScript 3.0

3. Instance Methods Revisited

In Chapter 1, we learned how to create instance methods. In this chapter, we’ll expand that basic knowledge by studying the following additional instance-method topics:

* Keyword this omission
* Bound methods
* State-retrieval and state-modification methods
* Get and set methods
* Extra arguments

Along the way, we’ll continue developing the virtual zoo program that we started in Chapter 1.

Posted by moock at 04:39 PM

March 15, 2007

Chapter 2, Paragraphs 1&2, Essential ActionScript 3.0

Here are the first two paragraphs of Chapter 2 of Essential ActionScript 3.0.

2. Conditionals and Loops

In this chapter, we’ll depart from the general topics of classes and objects. Instead, we’ll focus, on two essential types of statements: conditionals and loops. Conditionals are used to add logic to a program, while loops are used to perform repetitive tasks. Both conditionals and loops are extremely common, and can be found in nearly every ActionScript program. Once we’ve finished with conditionals and loops, we’ll return to classes and objects, and continue developing our virtual zoo program.

This chapter presents all code examples outside the context of a functioning class or program. However, in a real program, conditionals and loops can be used within instance methods, constructor methods, static methods, functions, directly within class bodies or package bodies, and even outside package bodies.

Posted by moock at 06:59 PM

March 14, 2007

Chapter 1, Paragraph 1, Essential ActionScript 3.0

over the next while I'll be posting the first paragraph or two from each chapter in Essential ActionScript 3.0.

here's chapter 1, paragraph 1...

1. Core Concepts

A program is a set of written instructions to be executed (i.e., carried out) by a computer or a software application. The written, human-readable text of a program is called source code, or just code. The person who creates a program is called a programmer, a coder, or a developer. Every program is written in a particular programming language, just as every book is written in a particular language (English, Russian, Japanese, etc). Programming languages dictate the syntax and grammar that programmers must use to form the instructions in a given program. This book provides from-the-ground-up coverage of the syntax, grammar, and usage of one specific programming language, ActionScript 3.0. Get ready for a good time.

Posted by moock at 07:17 PM

Essential ActionScript 3.0 Pre-ordering

Essential ActionScript 3.0 is now available for pre-order.

you can pre-order:
>> from amazon.com
>> from amazon.ca
>> from amazon.co.uk

if you order using the above link i get a small percentage of the sale (about $1-$2 i think). the commissions do add up, and are much appreciated as they help carry me through long research phases.

in general, if you are buying a book on programming, it's a Nice Thing to check if the author has a commission link you can use. if not, consider ordering the book through your local user group if they have a commission link.

Posted by moock at 07:12 PM

March 12, 2007

Essential ActionScript 3.0 Manuscript Complete

The final Essential ActionScript 3.0 manuscript has officially been sent to production. O'Reilly will now do some copy editing and layout, and will ship the printed book in June.

The final softcopy page-count is just over 900 pages. Final chapters should start appearing on rough cuts this month.

Here's the final table of contents:

Part I: ActionScript from the Ground Up (450 pages)

1 Core Concepts (41)
2 Conditionals and Loops (18)
3 Instance Methods Revisited (15)
4 Static Variables and Static Methods (10)
5 Functions (14)
6 Inheritance (29)
7 Compiling and Running a Program (7)
8 Datatypes and Type Checking (21)
9 Interfaces (13)
10 Statements and Operators (12)
11 Arrays (17)
12 Events and Event Handling (39)
13 Exceptions and Error Handling (27)
14 Garbage Collection (10)
15 Dynamic ActionScript (15)
16 Scope (8)
17 Namespaces (49)
18 XML and E4X (58)
19 Flash Player Security (48)

PART II: Display and Interactivity (357 pages)

20 The Display API and the Display List (46)
21 Events and Display Hierarchies (30)
22 Interactivity (51)
23 Screen Updates (23)
24 Programmatic Animation (18)
25 Drawing with Vectors (19)
26 Bitmap Programming (48)
27 Text Display and Input (66)
28 Loading External Display Assets (56)

PART III: Applied ActionScript Topics (55 pages)

29 ActionScript and the Flash Authoring Tool (36)
30 A Minimal MXML Application (5)
31 Distributing A Class Library (14)

Appendices
A The Final Virtual Zoo (15)

Posted by moock at 02:39 PM