Introduction to Flash and Actionscript

S4 - Buttons, Keyboard Commands, and HitTest

Assignment 5 - Collisions


Delete the dots when pacman hits them.

End the game when pacman hits a ghost.

Add an ending scene that gives the user the option to play again or return to the main menu

(You will need to have the last ghost event listener call the first)


To Move to a New Scene

When the game is over call the EndScreen funtion to delete any eventlisteners you do not need. You may also need to delete some of your movie clips.

When you move to a new scene you need to remove all event listeners and all










Above and Beyond

For both of these you will need to use a variable. Hints below but I will not solve this for you. (That is why it is above and beyond)

ICS3C students only need to do 1 of the items below. Bonus if you do both. Also I will help if you need an explanation.

1. Add a scoring system

Create a TextBox on the Stage

Make it Classic Text, Dynamic and embed it

Give it the instance name myScore_txt


Use a variable to hold the score
// Initialize score variable

var myScore:int;
myScore = 0


You can Modify the Properties of your text box

Use a function to print the score

// Use an ENTER_FRAME eventlistener


addEventListener(Event.ENTER_FRAME, printScore);



// Use a printScore function to print the score in a text box

// this will print the value intor the TextBox
myTextBox.text = "Score: " + String(myScore);

//On your dots hittest add one to the score

// to add to score
myScore +=1;


// To exit at a certain score put an if condition in the printScore function

// In the if remove the event listener and call your endScreen function


Note: You will need to move your dots off the stage or they will continue to add to the score


2. Hittest your walls in you hittest function, so that pacman cannot travel through them.


At the start of your program initialize a hit

var hit:Boolean; // A Boolean variable is either true or false


In a checkHit function

In the KeyDown Function modify your controls for hit true, or hit false

if (hit == false)


// All your normal commands


if (hit == true)


// move in opposite direction (incease number slightly)



The hittest will be slightly glitchy. We will learn how to make it better in the next assignment.