MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 319

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

5.
In Box.as, type the following ActionScript code into the Script window:
class Box implements IMovable {
public var xPos:Number;
public var yPos:Number;
public function Box() {
}
public function moveUp():Void {
trace("moving up");
// method definition
}
public function moveDown():Void {
trace("moving down");
// method definition
}
}
6.
Save your changes to the ActionScript document.
7.
Create a new Flash document named boxTest.fla, and then save it in the same directory as
the two previous ActionScript documents.
8.
Select Frame 1 of the Timeline, open the ActionScript editor, and then type the following
ActionScript code into the Actions panel (or Script window):
var newBox:Box = new Box();
This ActionScript code creates an instance of the Box class, which you declare as a variable
of the Box type.
9.
Save your changes to the Flash document, and then select Control > Test Movie to test the
SWF file.
In Flash Player 7 and later, you can cast an expression to an interface type or other data
type at runtime. Unlike Java interfaces, ActionScript interfaces exist at runtime, which
allows type casting. If the expression is an object that implements the interface or has a
superclass that implements the interface, the object is returned. Otherwise,
returned. This is useful if you want to ensure that a particular object implements a certain
interface. For more information on type casting, see
on page
111.
10.
Add the following code at the end of the ActionScript code in boxTest.fla:
if (IMovable(newBox) != null) {
newBox.moveUp();
} else {
trace("box instance is not movable");
}
Chapter 4, "About casting objects,"
Creating interfaces as data types
is
null
319

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents