flash on 2009-8-18
@adkOHTAH Aug 17 2009
Use your key to move the ball around the stage (Simple Movement)
♥0 |
Line 46 |
Modified 2009-08-18 03:11:08 |
MIT License
archived:2017-03-20 16:46:45
ActionScript3 source code
/**
* Copyright adkOHTAH ( http://wonderfl.net/user/adkOHTAH )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/4y6u
*/
/*
@adkOHTAH Aug 17 2009
Use your key to move the ball around the stage (Simple Movement)
*/
package
{
import flash.display.*;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class KeyMove extends MovieClip
{
private var object:Sprite;
public function KeyMove()
{
object = createMyObject(0xFF9900)
object.x = 200;
object.y = 100;
addChild(object);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedDown);
}
public function keyPressedDown(event:KeyboardEvent):void
{
var key:uint = event.keyCode;
switch(key)
{
case Keyboard.LEFT :
object.x -= 5;
break;
case Keyboard.RIGHT :
object.x += 5;
break;
case Keyboard.UP :
object.y -= 5;
break;
case Keyboard.DOWN :
object.y += 5;
break;
}
}
public function createMyObject(bgColor:uint):Sprite
{
var s:Sprite = new Sprite();
s.graphics.beginFill(bgColor);
s.graphics.drawCircle(0,0,40);
s.graphics.endFill();
return s;
}
}
}