![MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual Download Page 99](http://html1.mh-extra.com/html/macromedia/flash-mx-2004-actionscript/flash-mx-2004-actionscript_reference-manual_3378897099.webp)
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
.
Summary of Contents for FLASH MX 2004 - ACTIONSCRIPT
Page 1: ...ActionScript Reference Guide...
Page 8: ...8 Contents...
Page 12: ......
Page 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Page 54: ...54 Chapter 2 ActionScript Basics...
Page 80: ...80 Chapter 3 Writing and Debugging Scripts...
Page 82: ......
Page 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Page 112: ......
Page 120: ...120 Chapter 6 Using the Built In Classes...
Page 176: ......
Page 192: ...192 Chapter 10 Working with External Data...
Page 202: ...202 Chapter 11 Working with External Media...
Page 204: ......
Page 782: ...782 Chapter 12 ActionScript Dictionary...
Page 793: ...Other keys 793 221 222 Key Key code...
Page 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Page 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Page 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Page 816: ...816 Index...