Internet Commerce

Partners & Affiliates

Developer Channel


Featured Flash FLA
Gallery Downloads 11401 Flash Movies | 5 New Flash Movies Added
What's New | Top 100

Featured FLA

»  Author: Nick Kouvaris
»  Title: Znax
»  Description: Znax is a board game. Click 4 tiles of the same color and form squares as big as you can. You will erase all the tiles inside the square and collect points. Get maximum score if you make a square with game edges.
»  More by: Nick Kouvaris


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 4941 Flash Sites | 1 New Flash Links
What's New | Top 100 Flash Site

Featured Site

»  Author Agence WOP Digital Agency
»  Title: Electricdrum
»  Description: French WOP Agency, 3D websites, Flash (Papervision, Away 3D), event or institutional projects. The agency operates on all digital projects: consulting, design, graphic design, development, online communication. The WOP agency follows you on the implementation of original, creative and optimized digital projects.


Random Links | Add your own Flash Related Links
Flash Tutorials 1481 Tutorials 7 New Tutorials Added!
What's New | Top100

» How To Make A Simple Animation Using Christmas Clips
» Simple Step by step flash game tutorial Spot the diffrence
» How To Make A Moving Text Slide
» Create Flash Banner With Text Float Effect
» How To Make Zoo Photos Slideshow
» How To Make A Dolphin Photos Slideshow
» How To Make A Fathers Day Slideshow
» How To Make A Transparent Background of Your Flash File
» Create Flash Banner With Text Disco Light Effect Today we will introduce you a Text Disco Light eff
» Unknown Tag: Title10
Random Tutorial | Add Site


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Categories Implementing a hitTest array
Author: Chris Rhodes | Website: http://www.snakenetworks.com |

 
Page 2
«prev 1 2 3 4 5 next»

Implementation

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") {
 ticks++;
 if (ticks> 25) {
 this.duplicateMovieClip("ball"+i, i+10);
 _parent["ball"+i].name = i;
 _root.array[_root.arraysize] = i;
 _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){
 //trace(_root.array);
 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 ("");
 }
 }
}
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;
_root.arraysize++;
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.

«prev 1 2 3 4 5 next»

» Level Advanced

Added: : 2002-01-25
Rating: 8.37 Votes: 37
Hits: 4135
» Author
Chris 'PrED' Rhodes
» Download
Download the files used in this tutorial.
Download (5 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments