26.1.11

Using Classes

I created the external class files, which are all in the 'body' package, and hooked everything up. Let's look at the main class file, shall we?


package body  {

public class Jump {
   protected static constant STEP_AMOUNT:Number = 60
public var RedPressed:Boolean =  false
public var BluePressed:Boolean = false
public var YellowPressed:Boolean = false
public var OrangePressed:Boolean = false

At the bottom I added four booleans. These should help me with verification and error checking in the future. The step amount is standard.


        startRed():void
startBlue():void
startYellow():void
startOrange():void


internal function startRed():void {
Red.addEventListener(MouseEvent.CLICK, RedLeft);
Red.SetStepAmount(STEP_AMOUNT)
}


internal function startBlue():void {
Blue.addEventListener(MouseEvent.CLICK, BlueRight);
Blue.SetStepAmount(STEP_AMOUNT);
}


internal function startYellow():void {
Yellow.addEventListener(MouseEvent.CLICK, YellowDown);
Yellow.SetStepAmount(STEP_AMOUNT);
}


internal function startOrange():void {
Orange.addEventListener(MouseEvent.CLICK, OrangeUp);
Orange.SetStepAmount(STEP_AMOUNT);


I'm feeling kind of nervous about this part. It seems like it might lead to some weird looping problems. The functions are internal because they don't need to be accessed by any other class or instance. Their purposes are two-fold. First to add event listeners to each of the buttons, and then to send the standard STEP_AMOUNT integer to each of the four buttons.

No comments:

Post a Comment