CODE

Code

A snippet of code – this shows the code for the tapping main screen.

package {

import flash.display.MovieClip;
import flash.events.*;
import flash.display.*;
import flash.media.*;
import flash.utils.Timer;
import flash.net.SharedObject;

public class Tapping extends MovieClip {
public var moveTimer:Timer = new Timer(500);
public var scoreTimer:Timer = new Timer(50);
public var score:uint = 300;
public var loseSound:lose;
public var winSound:win;
public var soundControl:SoundChannel;

public function Tapping() {
// constructor code
//add listeners for the finishGame and addPoint listeners, reference in the hand class.
hand_mc.addEventListener(Hand.BAILED, finishGame);
hand_mc.addEventListener(Hand.WIN, addPoint);
//add timer for the scoring system.
scoreTimer.addEventListener(TimerEvent.TIMER, addScore);
scoreTimer.start();
//add timer for the hand movement.
moveTimer.addEventListener(TimerEvent.TIMER, moveHand);
moveTimer.start();
//add sounds.
loseSound = new lose();
winSound = new win();

}

//function using timer to make the hand move left.
private function moveHand(event:TimerEvent):void
{
hand_mc.x += -22;
}

//function to -2 every second of the score.
private function addScore(event:TimerEvent):void
{
score -= 2;
score_txt.text = String(score);
}

//function to show when the hand has hit the shake. Add sound. Remove hand movement timer.
// remove score timer. stop progress bar.
private function addPoint(event:Event):void
{
controlAudio(winSound);
progress.stop();
scoreTimer.removeEventListener(TimerEvent.TIMER, addScore);
scoreTimer.stop();
moveTimer.stop();
moveTimer.removeEventListener(TimerEvent.TIMER, moveHand);

ideaMain(parent).nextGame();

}

//function used to import sound, play once, and loudeness of sound.
private function controlAudio(snd:Sound):void
{
if (soundControl)
{
soundControl.stop();
soundControl = null;
}
var trans:SoundTransform = new SoundTransform(0.5);
soundControl = snd.play(0,0,trans);
}

//function to end the game when hand hits the alcohol. Lose sound, end timer and progress bar.
private function finishGame(event:Event):void
{
controlAudio(loseSound);
progress.stop();
scoreTimer.removeEventListener(TimerEvent.TIMER, addScore);
scoreTimer.stop()
moveTimer.stop();
moveTimer.removeEventListener(TimerEvent.TIMER, moveHand);

ideaMain(parent).gameOver();
}
}

}