Created
June 21, 2015 04:10
-
-
Save GSimas/0d3dadce64ab93dbaf42 to your computer and use it in GitHub Desktop.
AS2.0 Functions for Objects Control (Adobe Flash CS5)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var upPressed:Boolean = false; | |
var downPressed:Boolean = false; | |
var leftPressed:Boolean = false; | |
var rightPressed:Boolean = false; | |
bola.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey); | |
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed); | |
stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed); | |
function fl_MoveInDirectionOfKey(event:Event) | |
{ | |
if (upPressed) | |
{ | |
bola.y -= 5; | |
} | |
if (downPressed) | |
{ | |
bola.y += 5; | |
} | |
if (leftPressed) | |
{ | |
bola.x -= 5; | |
} | |
if (rightPressed) | |
{ | |
bola.x += 5; | |
} | |
} | |
function fl_SetKeyPressed(event:KeyboardEvent):void | |
{ | |
switch (event.keyCode) | |
{ | |
case Keyboard.UP: | |
{ | |
upPressed = true; | |
break; | |
} | |
case Keyboard.DOWN: | |
{ | |
downPressed = true; | |
break; | |
} | |
case Keyboard.LEFT: | |
{ | |
leftPressed = true; | |
break; | |
} | |
case Keyboard.RIGHT: | |
{ | |
rightPressed = true; | |
break; | |
} | |
} | |
} | |
function fl_UnsetKeyPressed(event:KeyboardEvent):void | |
{ | |
switch (event.keyCode) | |
{ | |
case Keyboard.UP: | |
{ | |
upPressed = false; | |
break; | |
} | |
case Keyboard.DOWN: | |
{ | |
downPressed = false; | |
break; | |
} | |
case Keyboard.LEFT: | |
{ | |
leftPressed = false; | |
break; | |
} | |
case Keyboard.RIGHT: | |
{ | |
rightPressed = false; | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment