Errata

ActionScript 3.0 Cookbook

Errata for ActionScript 3.0 Cookbook

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Other Digital Version online
In code download

In the downloadable code for the class DraggableSprite, it should look like this:

// Detect a drop by listening for mouse up on the stage
stage.addEventListener( MouseEvent.MOUSE_UP, mouseUp );
}

function mouseUp(e)
{ drop();
}

In your version you call drop() directly as an event handler, but that requires a parameter for the event object.

John Page  Aug 18, 2009 
Printed, PDF Page xviii
bottom paragraph

The ASCB library mentioned in the book is hosted on http://www.rightactionscript.com/ and it seems that domain/hosting expired. AFAIK, the mentioned code library cannot be downloaded from anywhere.

Anonymous  Aug 26, 2011 
Printed Page 35
6th (last paragraph) on the page - code example

The code example discusses a built-in arguments array and how to use it with a function.

The function looks like this in the book:

private function average():Number {

It actually should be specified as below:

private function average(... arguments):Number {

Having the ... arguments parameter tells the function to receive any number of arguments.

Michael Caruso  Jan 01, 2009 
Printed Page 117
5th or later

the result of the code "trace(newLetters)" is
"a,b,c" not "d,e,f"

the following is my testing code:
package edu.tongji.sse.number
{
import flash.display.Sprite;

public class TestArray extends Sprite
{
public function TestArray()
{
var letters:Array=["a","b","c"];
var newLetters:Array=letters;
trace("before change:");
trace("letters="+letters);
trace("newLetters="+newLetters);
letters=["d","e","f"];
trace("after chage:");
trace("letters="+letters);
trace("newLetters="+newLetters);

}
}
}

the result is:
before change:
letters=a,b,c
newLetters=a,b,c
after chage:
letters=d,e,f
newLetters=a,b,c

wangqichun  Apr 26, 2011 
Printed Page 127,128,130
127, last line; 128, 1st paragraph; 130 4th paragraph.

This is to support, and to add to, already reported (but so far unconfirmed) errors regarding sorting of arrays using a compare function (Page 127,128) and its application to random sorts (Page 130).

The last sentence starting on page 127 states: "The compare function then determines which one would be ordered first by returning a positive number, a negative number, or 0, depending on how the elements are to be sorted. If the function returns a negative number, a is ordered before b. If the function returns 0, then the current order is preserved. If the function returns a positive number, a is ordered after b."

It has already been reported that a compare function that returns 0 does not in fact preserve the current order. I can confirm that in this case the order is indeed changed from the original, and the additional fact that the resulting changed order is always the same each time the the sort function is called.

As for the negative and positive "numbers", the Adobe documentation refers to the compare function returning -1,0,or 1 to the sort function. Testing shows that any number <= -1 (i.e. -23.6) gives the same result as -1, and any number >= 1 gives the same result as 1. However, any positive or negative number between (but not equal to) -1 and +1 gives the same result as 0.

Because of this, the randomSort()compare function given on Page 130 does not in fact work as advertised. The function uses:

return Math.randonm() - 0.5

which returns numbers between -0.5 and +0.5, all of which are interpreted by the sort() function the same way as 0. Because, as noted above, the value 0 does in fact change the sort order, it appeared to me at first that this code was working. However, since it always gave the same order, I realized that something was amiss. It took me quite to understand the cause of the problem and to come up with exactly the same solution already reported (as I learned after the fact!), namely to use instead:

return Math.round(Math.random()*2)-1

This function returns values of either -1 or +1, and when passed to the array.sort() function, does exactly what is expected of it, i.e. the sort order changes each time the sort() function is called.

A slight modification of this function can be used to check the findings I am reporting:

return = x*(Math.round(Math.random()*2)-1)

If you set x >= 1 all works as expected: you get a different ordering each time the sort() function is used on the same array. If you set x to any value between (but not equal to) 0 and 1 (e.g. from 0.00000000000001 to .999999999999) you get a result identical to the result obtained by setting x = 0, namely a sort that is not the same as the original, but that is always the same from one call to the next.

Anonymous  Sep 11, 2008 
Printed Page 132
5th line

trace(letters1 == letters2];

Change bracket to parenthesis. Disarm nuclear bomb. Get the girl. Roll credits. In that order.

Anonymous  Dec 18, 2008 
Printed Page 147
Second paragraph, 10th line

...and no child7 is removed.

// I think it should read "child" w/o the 7.

Paul Hyman  Jul 10, 2009 
Printed Page 159
Lower third portion of code

The comment line for the button's over state currently says "//Create the display object for the button's up state". The line should actually say "over" instead of "up".

Christie Jensen  Feb 25, 2009 
Printed Page 229
start of second para

says: ...packaged in flash. display package -- should "display" be "text"?

dan hoagland  Jan 30, 2012 
Printed Page 231
Discussion Section of 9.3

The TextFieldType class is NOT contained in the flash.display package but in the flash.text

Anonymous  Jun 13, 2008 
Printed Page 232
Discussion Section of 9.4

the password property you describe in the book does not exist... its rather TextField.displayAsPassword = true

Anonymous  Jun 13, 2008 
Printed Page 331
Table 13-2

The example for the expression {n} states that 'creel' works and doesn't work.

Please clarify.

Anonymous  Sep 06, 2009 
Printed Page 357
Solution

The Timer class is in flash.utils NOT flash.util

Daniel Jarvis  Oct 12, 2009 
Printed Page 385
Code in Discussion section

var _sound:Sound = new Sound(new URLRequest("song.mp3"));
var channel:SoundChannel = _sound.play();
var transform:SoundTransform = new SoundTransform();
transform.volume = .5;
channel.soundTransform = transform;

The variable created named "transform" conflicts with Actionscript and needs to have a different name to operate correctly. Using "transform" as a name resulted in an error. I changed "transform" to "trans" throughout this code example and it worked fine.

Anonymous  Oct 14, 2008 
Printed Page 387
Top

import flash.media.SoundMixer;

is missing from the list of imports

Anonymous  Nov 02, 2008 
Printed Page 396
import statements, middle of page

import.flash.display.TextField;
should be
import.flash.text.TextField;

AND

import.flash.display.TextFieldAutoSize;
should be
import.flash.text.TextFieldAutoSize;

Margot Sheehan  Jul 12, 2009 
Printed Page 402
All of 16.10 Pausing and Resuming

The NetStream DOES NOT toggle between play/pause like its printed in the book... togglePause does that... pause() ONLY pauses and does NOT accept arguments like on the book... to resume we use the NetStream.resume() method.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html#pause()

Anonymous  Jun 13, 2008 
Printed Page 438
code example

So many flaws with this example. It's obvious the person who wrote it did not actually run it:

p 438
there is no 'flash.util.trace' class. You do not need to import anything to use trace.

p 438
loader.dataFormat = DataFormat.VARIABLES;
should be
loader.dataFormat = URLLoaderDataFormat.VARIABLES;

p 438
public class Example
must be amended to
public class Example extends MovieClip
or
public class Example extends Sprite
with the requisite
import flash.display.MovieClip;
or
import flash.display.Sprite;
added

and the flaw that started this ...

p 439
trace("someText = " + data.someText);
trace("someNumber = " + data.someNumber);
should be
trace("someText = " + loader.data.someText);
trace("someNumber = " + loader.data.someNumber);

In addition, using the same variable name, 'loader', is bad practice and could confuse new coders. The local variable name within handleComplete should not be the same as within the Example constructor. While technically valid, it's still bad form.

O'Reilly did not even remotely error check this book, it would appear.

oroboros  Oct 07, 2009 
Printed Page 475
example at top of page

Multiple errors in example script (example as written will NOT run).

Already confirmed error: import flash.util.* should be flash.utils.*

Not currently listed errata:

"loader.dataFormat = DataFormat.TEXT" should be "loader.dataFormat = URLLoaderDataFormat.TEXT"

In the definition of the function handleComplete() the passed variable is given the variable name of "event"...but half the code refer to the variable as "event" and the other half of the code, specifically in the catch statement, assumes the variable is named "e". This forces the catch to be tripped each time.

Since naming a variable similarly to a reserve word can cause confusion, the function would be best rewritten as:

private function handleComplete( e:Event ):void {
try {
// Convert the downloaded text into an XML instance
var example:XML = new XML(e.target.data);
// At this point, example is ready to be used with E4X
trace(example);

} catch ( e:TypeError ) {
// If we get here, that means the downloaded text could
// not be converted into an XML instance, probably because
// it is not formatted correctly.
trace( "Could not parse text into XML" );
trace( e.message );
}
}

As so many others have noted here, O'Reilly needs to start running the code it presents as examples - especially if a book is published before the final version of the software comes out - and then make sure that any errors discovered are corrected in future printings of the book. O'Reilly books did not used to have all of these mistakes...and as a programmer I need to be able to rely on the example code if I am teaching myself out of a book - because I will not be familiar enough with the syntax to catch the errors and separate bad examples from my own errors.

Caryn Coln  Nov 09, 2009 
Printed Page 488
5th Paragraph (21.1 discussion)

The line in the book is:
"This recipe discussed how to use the flex 2 solution for working with web services. For a Flash solution, see additional notes at http://www.rightactionscript.com/ascb"

There's no information in that location about web services or flash authoring for web services. The code libraries included also have no information or class reference to web services.

When deliberately writing a section that excludes part of the product you are talking about (AS3 for Flash, and not Flex) - and then "teasing" the reader with additional information... It should actually be supplied in the referenced location, or included in the book to begin with.

Anonymous  Mar 19, 2010