# Help with the mouse trail

**URL:** <https://forum.kirupa.com/t/help-with-the-mouse-trail/427124>\
**Category:** flash\
**Created:** [December 13, 2014, 2:48pm UTC](https://forum.kirupa.com/t/help-with-the-mouse-trail/427124 "2014-12-13T14:48:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![takshi\_murairi](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@takshi\_murairi](https://forum.kirupa.com/u/takshi_murairi)\
**Post date:** [December 13, 2014, 2:48pm UTC](https://forum.kirupa.com/t/help-with-the-mouse-trail/427124/1 "2014-12-13T14:48:32Z")

</div>

Hi,

I am working on a project in which i am planning to display a video as one of my final project for my video art elective. I want to make it interactive by adding a mouse trail on top of it so that viewers can leave a mark temporarily on it… the mouse trail’s example is in the link below. [http://www.inflexions.org/intothemidst.html](http://www.inflexions.org/intothemidst.html)

i have a code which i tried to fiddle with but i cudnt find a way around…

Can someone please guide me with the project…

Regards  
Moonis

package  
{  
import flash.display.Sprite;  
import flash.ui.Mouse;  
import flash.events.MouseEvent;  
import flash.events.Event;

```
public class MouseTrailer extends Sprite
{
	/* Light ball object */
	
	var lightBall:LightBall;
	
	/* Constructor */

	public function MouseTrailer():void
	{
		stage.addEventListener(MouseEvent.MOUSE_MOVE, startTrailer);
	}

	private function startTrailer(e:MouseEvent):void
	{
		/* Create a new LightBall object */

		lightBall = new LightBall();

		/* Position */

		lightBall.x = mouseX + Math.random() * lightBall.width;
		lightBall.y = mouseY - Math.random() * lightBall.height;
		
		/* Add to Stage */

		addChild(lightBall);

		/* Add Listener to Animate function */

		lightBall.addEventListener(Event.ENTER_FRAME, animate);
	}

	/* Animate function */

	private function animate(e:Event):void
	{
		/* Alpha */

		e.target.alpha -= 0.03;

		/* If lightBall is no longer visible, remove it */

		if (e.target.alpha <= 0.03)
		{
			e.target.removeEventListener(Event.ENTER_FRAME, animate);

			removeChild(e.target as Sprite);
		}

		/* Y Position */

		e.target.y += 0.9;
		
	}
}
```

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [December 15, 2014, 12:07am UTC](https://forum.kirupa.com/t/help-with-the-mouse-trail/427124/2 "2014-12-15T00:07:13Z")

</div>

What’s your question?

---

<div class="post-metadata">

**Author:** ![takshi\_murairi](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@takshi\_murairi](https://forum.kirupa.com/u/takshi_murairi)\
**Post date:** [December 16, 2014, 8:24pm UTC](https://forum.kirupa.com/t/help-with-the-mouse-trail/427124/4 "2014-12-16T20:24:41Z")

</div>

Can you please help on how i can attach the video coz i am really stuck bad.,. I tried everything but cant make it happen…  
my question is this. I have a video… and on the video i want to superimpose a mouse trail which should look like the one in the link ( [http://www.inflexions.org/intothemidst.html](http://www.inflexions.org/intothemidst.html))

I have a flash file in which i have the mouse trail similar to the above link, but the problem is i am not able to put the mouse trail over the video…

the code of the mouse trail is this…

var points:Array = new Array();  
var prev\_xmouse:Number;  
var prev\_ymouse:Number;  
this.onEnterFrame = function():Void {

this.clear();  
this.lineStyle(1.5, 0xcc0000);  
var dx:Number = this.\_xmouse - prev\_xmouse;  
var vx:Number = dx ? dx : Math.random() \* randSet(-1, 1);  
var dy:Number = this.\_ymouse - prev\_ymouse;  
var vy:Number = dy ? dy : Math.random() \* randSet(-1, 1);  
var pLen:Number = points.push({x:this.\_xmouse, y:this.\_ymouse, vx:vx / 3, vy:vy / 3, life:getTimer()});  
for (var i:Number = 0; i \< pLen; i++) {  
if (getTimer() - points[i].life \> 3000) {  
points.splice(i–, 1)[0];  
} else {  
if (i && points[i]) {  
points[i].x += points[i].vx;  
points[i].y += points[i].vy;  
var cx:Number = points[i - 1].x;  
var cy:Number = points[i - 1].y;  
this.curveTo(cx, cy, (points[i].x + cx) / 2, (points[i].y + cy) / 2);  
} else {  
this.moveTo(points[i].x, points[i].y);  
}  
}  
}  
prev\_xmouse = this.\_xmouse;  
prev\_ymouse = this.\_ymouse;  
};  
function randSet():Number {  
return arguments[Math.floor(Math.random() \* arguments.length)];  
}

so the question is how do i import the video which will serve the background and on it the mouse trail will work…

thanks
