First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Chris Rhodes | Website: http://www.snakenetworks.com

The normal ball

If we look at the script for if our ball’s name is not ‘ballParent’ we will see the following.
As you may have seen, the original ball’s name is ballParent, but when we duplicate the clip, we give it another name, that means that it will NOT execute the definition of the array again etc.
On load, we define its _x value as a random position on the screen, give it a falling speed (random of course), and a variable called ‘move’ which is set to 1. This move variable is quite important, when it is set to 1, the clip will go about its job normally, however when it is set to 0, the clip will remove itself from the scene. If move is equal to 1, we have 4 or so simple lines of code to move it down by its speed every frame, then if it is lower than the screen to set ‘move’ to 0 (to remove itself) Now if ‘move’ is set to 0, we must remove the clip’s name from the array, this is the most difficult part of this tutorial to understand so bear with me, again here is the code:
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];
		_root.arraysize--;
		i = _root.arraysize;		
	}
}
removeMovieClip ("");
What this code does is as follows: Step through the array one by one, and compare that value to the balls own ‘name’ (given on duplication). If the name in the array is equal to its own name, we then continue through the array but put the next element onto the current element, in essence, once we step the array back 1, from the point where we found our ‘name’, we are deleting it, as it is no longer in the array. We then remove the final element (as it is just a copy of the last element) Here is a little picture of what we do to help you understand. Array, (arraySize == 5) : |0|1|2|3|4| If we remove the ‘2’ we step all the other elements from 3 on back one. Array, (arraySize == 5) : |0|1|3|4|4| Then we delete the last element. Array, (arraySize == 4) : |0|1|3|4| We are left with the array we want.
» 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!

Comments

  • 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.