Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.display.MovieClip;
- import flash.events.*;
- import flash.ui.Keyboard;
- public class robot extends MovieClip {
- private var _root: Object;
- private var speed: int = 5;
- public function robot() {
- // constructor code
- addEventListener(Event.ADDED, beginClass);
- }
- private function beginClass(e: Event): void {
- _root = MovieClip(root);
- stage.addEventListener(KeyboardEvent.KEY_DOWN, moveRobot);
- }
- private function moveRobot (e: KeyboardEvent): void {
- if (e.keyCode == Keyboard.UP) {
- y -= speed;
- }
- if (e.keyCode == Keyboard.DOWN) {
- y += speed;
- }
- //code to stop going off screen
- if ((this.y - (this.height / 2)) < 0) {
- y = (0 + this.height / 2);
- }
- if ((this.y + (this.height / 2)) > 400) {
- y = (400 - this.height / 2);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement