After putting the main body in place, I proceeded to add the class files for each of the directional buttons, to give them functionality.
package body {
import flash.utils.Timer;
public class RedLeft {
private static constant DIRECTIONAL:Number = -1
private var _StepAmount:Number = 0
private var resetTimer:Timer = new Timer (250, 1);
resetTimer.addEventListener(TimerEvent.TIMER_COMPLETE, reset);
The DIRECTIONAL number is the directional coefficient for each direction, to let the program know what direction to go in on each axis. The purpose of the resetTimer will soon be revealed.
private function Jump():void {
if (BluePressed) {BlueRight.stop(); && BluePressed = false}
RedPressed = true
var lug:Number = DIRECTIONAL * StepAmount
Green.x += lug
}
I added the BlueRight.stop() to the private Jump function but I have no idea if it will work. This is a stand-in line of code for when I upgrade the Jump EX to work with the soon-to-be-made Push Ex and Accelerate/Decellerate EX. Lug is the final number of pixels that the object will move on the specified axis.
internal function SetStepAmount(value:number):Number
{
if isNaN(value){throw new Error ("Pivotal Variable is of the wrong type.")
}
else
{
_StepAmount = value
}
Either the internal part means that the function is accessible within the package or I messed up. I'm doing my first error check here as well. I want to make sure that I'm dealing with a number only.
internal function GetStepAmount();
{
return _StepAmount
}
public function RedLeft(event:MouseEvent):void
{
Jump(Axis, DIRECTIONAL);
}
internal function reset();
{
RedPressed = false
}
I will probably end up having to change GetStepAmount to GetRedStepAmount to disambiguate for the other class files that need it. Right below it the publick function RedLeft(event:MouseEvent):void, the bread and butter of the program. Finally, the reset function sets the boolean back to false.
No comments:
Post a Comment