import mx.events.EventDispatcher; class Player extends MovieClip { var speed:Number; var nextx:Number; var lbound:Number; var rbound:Number; var fireKeyWait:Number = 0; static var FIRE_WAIT_FRAMES = 7; public function Player () { EventDispatcher.initialize(this); speed = 5; fireKeyWait = 0; lbound=0; rbound = Stage.width; nextx = _x; } function setLocation(x,y) { _y = y; _x = x; nextx = _x; } function setSpeed(val:Number) { speed = val; } function getSpeed():Number { return speed; } function setBounds(right:Number, left:Number) { rbound=right; lbound=left; } function Move() { if (Key.isDown(Key.LEFT)) { if (_x-speed > lbound) { nextx -= speed; } } if (Key.isDown(Key.RIGHT)) { if (_x+speed < rbound) { nextx += speed; } } fireKeyWait++; if (Key.isDown(Key.SPACE) && fireKeyWait > FIRE_WAIT_FRAMES) { this.dispatchEvent({type:"EventFireMissile"}); fireKeyWait=0; } } function Render() { _x = nextx; } public function addEventListener(){/*Interface Stub*/} public function removeEventListener(){/*Interface Stub*/} public function dispatchEvent(){/*Interface Stub*/} }