First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Chris Rhodes | Website: http://www.snakenetworks.com


For this tutorial I will be making a really basic game where balls fall from the ‘roof’ and you must stop them with a paddle, I have excluded any scoring/end game flags to keep this as pure as possible.

The parentBall

Firstly draw a circle on the main timeline, select it, and create a movieClip out of it (F8). Now select the circle, and in the ‘Instance Toolbar’ set its name to ‘ballParent’. Then right click on the circle and select: Actions. Now the first bit of actionScript we need is following.
onClipEvent (load) {
	if (_name == "ballParent") {
		_visible = 0;
		_root.array = new Array();
		_root.arraySize = 0;
		ticks = 0;
		i = 0;
	} else {
		_x = _width/2+random(550-_width/2);
		speed = 2 + random(4);
		move = 1;
All this does is the following: If the balls name is ‘ballParent’ (which it is) we will create a new array on the root of the movie called ‘array’. This will be the array that holds the names of the duplicated balls. We also create a variable called ‘arraySize’ on the root of the movie. This will be used to check the size of the array. Finally we create two more variables which will be used later. If the balls name is not ballParent, we defined some other variables which I will describe later. Next add the following code:
onClipEvent (enterFrame) {
	if (_name == "ballParent") {
		if (ticks > 25) {
			this.duplicateMovieClip("ball"+i, i+10);
			_parent["ball"+i].name = i;
			_root.array[_root.arraysize] = i;
			ticks = 0;
	} else {
		if (move == 1) {
			_y += speed;
			if(_y > 410){
				move = 0;
		} else {
			for(i = 0;i < _root.arraysize;i++){
				if(_root.array[i] == name){
					for(j = i;j < _root.arraysize-1;j++){
						_root.array[j] = _root.array[j+1];
					delete _root.array[_root.arraysize];
					i = _root.arraysize;
			removeMovieClip ("");

This is the ‘heart’ of the system. First I will explain at the code for the ballParent. Every frame ticks is increased by one, if ticks is greater than 25, we then duplicate the ballParent. This will give us our duplicatedBalls. Every time a ball is duplicated we give it its array-name. If the ball is ‘ball0’ then its array-name will be ‘0’ (I am using integers to keep the memory usage lower, however we could make its name its actual name using the _name expression). Then we add this array-name to the array. I will describe what is happening.
_root.array[_root.arraysize] = i;
For example, if the array is of size ‘0’, then we need to give the first element the array-name of our duplicated ball. If the array is of size ‘5’ then the 6th element must be given the name. Because an array’s first element is in fact 0, we can just say: ARRAYNAME[ARRAYSIZE] = NAME We then increase the array size, and increment i.
» Level Advanced

Added: 2002-01-25
Rating: 9 Votes: 36
(10 being the highest)
» Author
Chris 'PrED' Rhodes
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.