Help with particles heading to target

Hey!

I got the following code online to make particles head to a specific location on screen. I can’t get it to work, though, because i’m not sure where to put which part of the script. (ie on timeline or movieclip).

i can’t get it to work.

can anyone help out? the script might be useful to others too!

thanks!
S

speed =20;

target_x= //some number
target_y= //some number

tanx= target_x-this._x;
tany= target_y-this._y;
radangle = Math.atan2(tany,tanx);
this._rotation = radangle*180/Math.PI; // this is to point it in the right direction if you need to
deltay = speed * Math.sin(radangle);
deltax = speed * Math.cos(radangle);

function bombTarget(){
if(deltax<0){
if(target_x < this._x){
this._x += deltax;
this._y += deltay;
}
if(this._x <= target_x ){
bombing = false;
gotoAndPlay(2);
}

	}
	if(deltax&gt;0){
		if(target_x &gt; this._x){
			this._x += deltax;
			this._y += deltay;
		}
		if(this._x &gt;= target_x){
			bombing = false;
			gotoAndPlay(2);
		}
		
	}

}

i have the function as bombtarget but you can change it to whatever you want.

onClipEvent(enterFrame){
if(bombing){
bombTarget();
}
}