EasyManua.ls Logo

MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT - Page 99

MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT
816 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Creating interactivity and visual effects 99
8 Use similar code to check if the Left Arrow, Up Arrow, or Down Arrow key is being pressed.
Your code should look like this:
var distance = 10;
car.onEnterFrame = function() {
with (car) {
if (Key.isDown(Key.RIGHT)) {
_x += distance;
if (_x >= 400) {
_x = 400;
}
_root.display_txt.text = "Right";
} else if (Key.isDown(Key.LEFT)) {
_x -= distance;
if (_x < 0) {
_x = 0;
}
_root.display_txt.text = "Left";
} else if (Key.isDown(Key.UP)) {
_y -= distance;
if (_y < 0) {
_y = 0 ;
}
_root.display_txt.text = "Up";
} else if (Key.isDown(Key.DOWN)) {
_y += distance;
if (_y > 300) {
_y = 300;
}
_root.display_txt.text = "Down";
}
}
}
9 Select Control > Test Movie to test the file.
For more information about the methods of the Key class, see the Key class entry in Chapter 12,
ActionScript Dictionary,” on page 205.

Table of Contents

Related product manuals