Search tutorials
Step 2
Add a second layer to the main timeline called actions On the first keyframe of the actions layer, add this actionscript:Movieclip.prototype.distance=function(moviec){
if(typeof(moviec) == "string"){
moviec=eval(moviec)
}
var temp=new Object()
temp.distx=moviec._x-this._x
temp.disty=moviec._y-this._y
temp.distance=Math.sqrt((temp.distx*temp.distx)+(temp.disty*temp.disty))
if (temp.distx>0) {
temp.directionx=1;
}
else {
temp.directionx=-1;
}
if (temp.disty>0) {
temp.directiony=1;
}
else {
temp.directiony=-1;
}
return temp
}
This sets up a function that can be applied to our movieclips and returns an object containing the following data:distx=distance between two clips on the x axis
disty=distance between two clips on the y axis
distance=distance between two clips in a straight line
directionx & directiony=numbers that are 1 or -1 depending on whether movieclip1 is above or below or left of or right of movieclip2
| » Level Intermediate |
|
Added: 2002-04-11 Rating: 6 Votes: 80 |
| » Author |
| Engineering student who lieks flash. |
| » Download |
| Download the files used in this tutorial. |
| Download (4 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


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