
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
56
|
Chapter 3: Datatypes and Type Checking
Similarly, the following attempt to store a number returned by getBytesLoaded( ) in a
String variable does not generate an error when the code is placed on a frame:
// No error. (Should be a type mismatch error.)
var msg:String = _root.getBytesLoaded( );
Furthermore, assigning the current MovieClip instance (this) to a non-MovieClip
variable or passing the current MovieClip instance (
this) to a non-MovieClip func-
tion 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.)
These problems occur only within code on a frame in a timeline, because on a time-
line, nested movie clips are treated as dynamic properties of the containing movie
clip. ActionScript 2.0 does not type check dynamic properties. However, within an
ActionScript 2.0 class, type checking works properly with MovieClip instances.
To ensure proper type checking for movie clips within timeline code, first assign the
MovieClip instance in question to a variable of type MovieClip, and use that variable
in place of the MovieClip instance reference. ...