Errata

ActionScript 3.0 Programming: Overview, Getting Started, and Examples of New Concepts

Errata for ActionScript 3.0 Programming: Overview, Getting Started, and Examples of New Concepts

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
Printed Page 15
2nd Paragraph (Example 5)

Following the instructions, I get the following Runtime error:

ArgumentError: Error #1063: Argument count mismatch on TextLoader$iinit(). Expected 1, got 0.

(41/42) AS script covering page 41 to 42;
I'm not sure where the error is (or indeed, if there is an error!) but when I test this script as per
the authors instructions I get an error as below:

"5006: An ActionScript file can not have more than one externally visible definition: FlashBtn, BtnState

Anonymous   
PDF Page 41
Example 12

// 1) An ActionScript 3.0 file can have only one public class
// 2) A private class cannot be nested inside a public class,
// such as the constructor, which is the difficulty with
// this example.

Corrected Code...
package
{
// The Public Class needs the functionality of just the SimpleButton
import flash.display.SimpleButton;

public class FlashBtn extends SimpleButton
{
public function FlashBtn(txt:String)
{
upState = new BtnState(0xfff56d, txt);
downState = new BtnState(0xfff222, txt);
overState= new BtnState (0xfff000,txt);
hitTestState=upState;
useHandCursor=true;
}
}
// the class BtnState cannot be declared here, it must
// be moved to a place after the Package constructor
// along with the required import declarations
}

// Private class within this package...

// 1) An ActionScript file can only have ONE public class.
// 2) To make private classes they MUST BE OUTSIDE THE PACKAGE
// DECLARATION.
// 3) Imports for additional private classes must be AFTER the
// Package construct.
// 4) Imports within the Package construct are not visible to
// classes outside the Package construct, this condition may
// require duplicate declarations in some ActionScript files.
// 5) NO DECLARATIONS can be placed before the Package keyword,
// this must be the first scripting word in the ActionScript
// file, only comments can precede the Package keyword.
// 6) The ActionScript class that is extended by the private
// class must be declared before and outside of the private
// class

import flash.display.Sprite;

// These can be declared here or inside the private class as shown
// below, it just depends on how you want to scope the declarations

//import flash.display.Shape;
//import flash.text.TextFormat;
//import flash.text.TextField;
//import flash.text.TextFieldAutoSize;

class BtnState extends Sprite
{

import flash.display.Shape;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;

private var btnLabel:TextField;
public function BtnState(color:uint,btnLabelText:String):void
{
//Text field for button
btnLabel = new TextField();
btnLabel.text=btnLabelText;
btnLabel.autoSize=TextFieldAutoSize.LEFT;

//Text format for text field
var format:TextFormat = new TextFormat("Verdana");
format.size=12;
btnLabel.setTextFormat(format);
var btnWidth:Number=btnLabel.textWidth + 10;

//Shape for button background
var bkground:Shape = new Shape();
bkground.graphics.beginFill(color);
bkground.graphics.lineStyle(2,0xf3c716);
bkground.graphics.drawRect(0,0,btnWidth,18);

addChild(bkground);
addChild(btnLabel);
}
}

Anonymous  Jul 26, 2008 
Printed Page 42
First third

In example 12 you have the code:

class BtnState extends Sprite
....

The class definition has to be in a different file BtnState.as

Anonymous   
Printed Page 42
Example 12

I'm following up with an earlier report of an error ("5006: An ActionScript file can not have more than
one externally visible definition: FlashBtn, BtnState") when attempting to run examples 12 and 13 in
Flash CS3.

After looking around at some discussions on the web, it looks like having two class definitions in the
same package is no longer allowed the the prodction version of AS3 (it was permitted in alpha, but has
since been removed). Two ways to fix it are...

1. Create a new file (BtnState.as) that includes the class definition.

2. Move the BtnState definition (as well as the relevant include statements) _outside_ of the package {}
chunk of code.

Anonymous