MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual page 99

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Use similar code to check if the Left Arrow, Up Arrow, or Down Arrow key is being pressed.
8
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";
}
}
}
Select Control > Test Movie to test the file.
9
For more information about the methods of the Key class, see the
"ActionScript Dictionary," on page
205.
Creating interactivity and visual effects
Key class
entry in
Chapter 12,
99

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?

Questions and answers

Table of Contents