I'm trying to simulate gravitational acceleration by constructing a function that will subtract from the Player object's yVelocity every half a second.Code:package { import flash.display.MovieClip; import flash.events.TimerEvent; import flash.utils.Timer; public class Player extends MovieClip { spawn(); //Constructs Registration Areas aroud Player public var fReg:FloorReg; public var rReg:RightReg; public var lReg:LeftReg; public var cReg:CeilingReg; private var Time:Timer; public function Player() { //This is adding registration areas to the display object and can be ignored var oHeight:Number = this.height fReg = new FloorReg(0, this.height, this.height / 4, this.width); addChild(fReg); rReg = new RightReg(this.width, 0, this.height - fReg.height, this.width / 4); addChild(rReg); lReg = new LeftReg(this.width / -4, 0, this.height - fReg.height, this.width / 4); addChild(lReg); cReg = new CeilingReg(0, this.height / -5, oHeight / 4, oHeight); addChild(cReg); //threw in a new Timer object, Time = new Timer(500, 0); } private function spawn():void { //direct player object to it's spawning animation and initialize the Fall function trace("spawnd"); Time.start(); fall(); } //Constructs velocity vars private var yVel:Number = 0; private var xVel:Number = 0; public const TERMINAL_VELOCITY:Number = -7; private function fall():void { if (yVel > TERMINAL_VELOCITY) { Time.addEventListener(TimerEvent.TIMER, gravity); } } private function gravity(event:TimerEvent):void { do { yVel--; } while(yVel > TERMINAL_VELOCITY) Time.removeEventListener(TimerEvent.TIMER, gravity); } } }
For now, I'm getting 1180:Call to a possibly undefined function spawn
but I'm sure there are other things wrong with the code, I'm quite new at this whole 'event flow' stuff so that could very well be the issue. Thanks in advance!![]()




Reply With Quote
