By Colin Moock
Book Price: $39.95 USD
£28.50 GBP
PDF Price: $31.99
Cover | Table of Contents | Colophon
http://www.mozilla.org/js/language/es4.http://www.mozilla.org/js/language/es4.prototype
property but could also be established
via the _ _proto_ _ property. Inheritance is
covered in Chapter 6.http://www.macromedia.com/exchange/flash), in
the User Interface category, under the title "Flash
MX Components for Flash MX 2004."r) is
given a _ _proto_ _ property that refers to
Rectangle.prototype, again making it look to the
Flash Player just like its ActionScript 1.0 counterpart.var variableOrPropertyName:datatype;
var ball1:Ball = new Basketball( ); // Legal!
var ball2:Basketball = new Ball( ); // Illegal!
ball1, whose declared datatype is
Ball. The compiler allows this even though the
Basketball subclass might define methods and
properties not supported by the Ball superclass.
However, the compiler displays an error if we try to access a method
or property on ball1 that isn't
supported by the Ball class (i.e., the datatype
of ball1) even if such method or property is
defined for the Basketball class. For example,
suppose that the Basketball subclass defines an
var dataSender:LoadVars = new LoadVars( );
dataSender.firstName = "Rebecca"; // No error, even though
// the LoadVars class doesn't
// define the firstName property.x, but does not
declare x's datatype:var x = 10;
x is not typed, type checking
is not (indeed cannot be) performed, and
x's datatype can be changed
without generating an error:x = "hello"; // Change from Number to String.
x causes no error:trace(x._width); // No error. Returns undefined if _width doesn't exist. x.flyToTheMoon( ); // No error. // Fails silently if flyToTheMoon( ) doesn't exist.
function combine (x, y) {
return x + y;
}
// Pass values with different datatypes to x and y.
// No errors occur because the parameters x and y are not typed.
trace(combine(4,5)); // Displays: 9
trace(combine("hello ", "world")); // Displays: hello world
trace(combine(_root, "hello world")); // Displays: _level0hello world
Type(object);
(
Type
)
object
should note that in ActionScript 2.0's cast syntax,
the parentheses surround the object, not the type name. That is,
ActionScript's type casting resembles the form of a
function call.obj, then assign obj to the
variable tf, whose type is
TextField. Before assigning
obj to tf, we cast
obj to the TextField
datatype:var obj:Object = new Object( ); var tf:TextField = TextField(obj);
TextField(obj) tricks the compiler into believing
that obj is a TextField.
Without the cast, the compiler would generate a type mismatch error.
With the cast, the compiler generates no error because it considers
the variable obj to be a
TextField instance, which is compatible with the
datatype of tf. Refer to the earlier discussion
under "Compatible Types" for an
explanation of why storing an TextFormat.align property requires a
String, but a Boolean is
used:var tf:TextFormat = new TextFormat( ); tf.align = true; // Error! Boolean values not allowed.
_global
object, as follows:_global.varname = value;
_global.author:String = "moock"; // Output panel displays: Syntax error.
_y does not generate a compile-time type mismatch
error when the code is placed on a frame in a timeline:_root._y = "test"; // No error. (Should be a type mismatch error.)
// No error. (Should be a type mismatch error.) var msg:String = _root.getBytesLoaded( );
this) to a
non-MovieClip variable or passing the current
MovieClip instance (this) to
a non-MovieClip function parameter causes no
error. For example, when placed on a frame in a timeline, the
following examples yield no error:var x:String = this; // No error. (Should be a type mismatch error.)
function square(x:Number):Number {
return x * x;
}
square(this); // No error. (Should be a type mismatch error.)class keyword,
as follows:class ClassIdentifier {
}
class Box {
}
class
keyword anywhere else—such as on a keyframe or a
button—generates a compile-time error. Furthermore, each
.as file can contain only one class definition
and must have a filename exactly matching the name of the class it
contains (case sensitivity matters!).width and height properties)class Box {
public function Box ( ) {
}
}