flash on 2012-9-21
♥0 |
Line 56 |
Modified 2012-09-21 21:30:49 |
MIT License
archived:2017-03-30 22:59:18
ActionScript3 source code
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/aUIg
*/
package {
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.display.Graphics;
import flash.text.engine.SpaceJustifier;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public var ps:Sprite;
public function FlashTest() {
// write as3 code here..
ps = new Sprite();
var g:Graphics;
g = ps.graphics;
g.clear();
g.lineStyle(2,0);
g.drawCircle(0,0,8);
g.moveTo(0,0);
g.lineTo(8,0);
addChild(ps);
ps.x = 200;
ps.y= 200;
stage.addEventListener(Event.ENTER_FRAME, onEnter);
stage.addEventListener(KeyboardEvent.KEY_DOWN, kdown);
stage.addEventListener(KeyboardEvent.KEY_UP, kup);
}//ctor
public var vecKey:Vector.<Boolean> = new Vector.<Boolean>(512,false);
public function kdown(e:KeyboardEvent):void
{ vecKey[e.keyCode] = true;}
public function kup(e:KeyboardEvent):void
{ vecKey[e.keyCode] = false;}
public var vx:Number = 0;
public var vy:Number = 0;
public var va:Number = 0;
public function onEnter(e:Event):void
{
if (vecKey[Keyboard.LEFT]) { vx -= 0.4;}
if (vecKey[Keyboard.RIGHT]) { vx+=0.4;}
if (vecKey[Keyboard.UP]) { vy -= 0.4;}
if (vecKey[Keyboard.DOWN]) { vy += 0.4;}
vx *= 0.99;
vy *= 0.99;
if (ps.x<10) { ps.x = 10; vx=0;}
if (ps.x > 390) { ps.x = 390; vx =0;}
if (ps.y < 10) { ps.y = 10; vy =0;}
if (ps.y > 390) { ps.y= 390; vy = 0;}
ps.x += vx;
ps.y += vy;
var dx:Number;
var dy:Number;
dx = mouseX - ps.x;
dy = mouseY - ps.y;
va = Math.atan2(dy, dx);
ps.rotation = va * (180/3.1415);
}//onenter
}//classend
}