A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11337 Flash Movies | 1 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Bugra Ozden
» Title: Skatalog v9 - product catalog
» Description: Create your product catalog easly and publish on your website or Create your image gallery, documents list, portfolio. Fully XML Driven
» More by Bugra Ozden


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

Featured Site

» Posted in the Flash Kit Links section
» Title: Creative DW Image Show PRO
» Description: Creative DW Image Show PRO is a Dreamweaver extension which enables the user to create multimedia presentations. It combines the features of the popular Creative DW Image Show with the ability to add professional text effects to slides (similar to After Effects). The product is very customizable: the user can choose the duration of the transition effects, the slide motion start and end position, zoom and panning type for both images and texts.


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

» Make a Flash Slide Show Screen Saver
» Simple flash making tutorial for thanksgiving
» Create flash banner for website
» Create xml slideshow with free template
» How to Insert a Multilingual Subtitle Into Your Flash Video Studio
» How to Create Cool Halloween Slideshow
» Debugging flash using the Firebug console
» Create Flash Slideshow on Blogger
» FLASH TRICKS IN WEB ADVERTISING: FLASH BANNERS
» Unknown Tag: Title10
Random Tutorial | Add Site

Trading Customer Accounting (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume


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.48 Votes: 35
Hits: 4131
» 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
 
   
 

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs