# How to change mouse trailer script so it follows the path

**URL:** <https://forum.kirupa.com/t/how-to-change-mouse-trailer-script-so-it-follows-the-path/310013>\
**Category:** flash\
**Created:** [May 30, 2010, 6:59am UTC](https://forum.kirupa.com/t/how-to-change-mouse-trailer-script-so-it-follows-the-path/310013 "2010-05-30T06:59:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![trumpp](https://avatars.discourse-cdn.com/v4/letter/t/dc4da7/32.png) [@trumpp](https://forum.kirupa.com/u/trumpp)\
**Post date:** [May 30, 2010, 6:59am UTC](https://forum.kirupa.com/t/how-to-change-mouse-trailer-script-so-it-follows-the-path/310013/1 "2010-05-30T06:59:01Z")

</div>

Hi! I found nice dynamic mouse traile which i’d like to use on my flash banner. I can get rid of mouse actions but how do make random sparkles move from left side of banner to the right side? Here is mouse trailer code:

//import bitmap class  
import flash.display.BitmapData;  
//Settings  
var particleMaxSpeed:Number = 3;  
var particleFadeSpeed:Number = 5;  
var particleTotal:Number = 5;  
var particleRange:Number = 25;  
/\*\*

- createExplosion(target X position, target Y position)  
\*/  
function createExplosion(targetX:Number, targetY:Number):Void  
{  
//run for loop based on particleTotal  
for (var i:Number = 0; i\<particleTotal; i++) {  
//attach bitmap from the library with the linked name “adobe\_flash”  
var myBmp:BitmapData = BitmapData.loadBitmap(“fire.jpg”);

//create the “main\_holder” movieclip that will hold our bitmap  
var particle\_mc = \_root.createEmptyMovieClip(“main\_holder”, \_root.getNextHighestDepth());

//create an “internal\_holder” movieclip inside “main\_holder” that we’ll use to center the bitmap data  
var internal\_holder:MovieClip = particle\_mc.createEmptyMovieClip(“internal\_holder”, particle\_mc.getNextHighestDepth());

//set “internal\_holder” x and y position based on bitmap size  
internal\_holder.\_x = -myBmp.width/2;  
internal\_holder.\_y = -myBmp.height/2;

//finally, attach the bitmapData “myBmp” to the movieclip “internal\_holder”  
internal\_holder.attachBitmap(myBmp, internal\_holder.getNextHighestDepth(), “never”, true);

//set position & rotation, alpha  
particle\_mc.\_x = targetX  
particle\_mc.\_y = targetY  
particle\_mc.\_rotation = random(360);  
particle\_mc.\_alpha = random(50)+50;

//set particle boundry  
particle\_mc.boundyLeft = targetX - particleRange;  
particle\_mc.boundyTop = targetY - particleRange;  
particle\_mc.boundyRight = targetX + particleRange;  
particle\_mc.boundyBottom = targetY + particleRange;  
//set speed/direction of fragment  
particle\_mc.speedX = Math.random(particleMaxSpeed)-Math.random(particleMaxSpeed);  
particle\_mc.speedY = Math.random(particleMaxSpeed)-Math.random(particleMaxSpeed);  
particle\_mc.speedX \*= particleMaxSpeed  
particle\_mc.speedY \*= particleMaxSpeed

//set fade out speed  
particle\_mc.fadeSpeed = Math.random(particleFadeSpeed)\*particleFadeSpeed;

//just a visual particle counter  
numberOfParticles++;  
//make fragment move using onEnterFrame  
particle\_mc.onEnterFrame = function():Void  
{  
//update alpha, x, y  
this.\_alpha -= this.fadeSpeed;  
this.\_x += this.speedX;  
this.\_y += this.speedY;  
//if fragment is invisible or out of bounds, remove it  
if (this.\_alpha \<= 0 || this.\_x \< this.boundyLeft || this.\_x \> this.boundyRight || this.\_y \< this.boundyTop || this.\_y \> this.boundyBottom)  
{  
this.removeMovieClip();  
//  
numberOfParticles–;  
}  
}  
}  
}  
/\*\*

- Mouse Controls  
\*/  
//create an object that we’ll listen to  
mouseListener = new Object();  
//on Click, createExplosion  
mouseListener.onMouseDown = function() {  
//createExplosion(\_xmouse, \_ymouse);  
}  
mouseListener.onMouseMove = function() {  
createExplosion(\_xmouse, \_ymouse);  
}  
//add listener  
Mouse.addListener(mouseListener);

I’ll appreciate any help. Thank you!
