Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. package {
  2. import flash.display.MovieClip;
  3. import flash.events.*;
  4. import flash.ui.Keyboard;
  5.  
  6. public class robot extends MovieClip {
  7. private var _root: Object;
  8. private var speed: int = 5;
  9.  
  10. public function robot() {
  11. // constructor code
  12. addEventListener(Event.ADDED, beginClass);
  13. }
  14.  
  15. private function beginClass(e: Event): void {
  16. _root = MovieClip(root);
  17. stage.addEventListener(KeyboardEvent.KEY_DOWN, moveRobot);
  18. }
  19.  
  20. private function moveRobot (e: KeyboardEvent): void {
  21. if (e.keyCode == Keyboard.UP) {
  22. y -= speed;
  23. }
  24.  
  25. if (e.keyCode == Keyboard.DOWN) {
  26. y += speed;
  27. }
  28.  
  29. //code to stop going off screen
  30. if ((this.y - (this.height / 2)) < 0) {
  31. y = (0 + this.height / 2);
  32. }
  33.  
  34. if ((this.y + (this.height / 2)) > 400) {
  35. y = (400 - this.height / 2);
  36. }
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement