|
|
Search Tutorials
Step 2Add 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
|
||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||
|