Custom Mouse Pointer

Experimental Drawing Script

We learned some extremely important scripting skills this exercise.... skills you will use over and over again as long as you are an ActionScipt 2.0 programmer. We jumped a little bit ahead by looping these actions and setting the x,y position of a movieClip to the x,y position of the mouse, but you will get it with practice.

As a quick review:

  1. The onEnterFrame() function is used to loop actions
  2. Set variable is used to dynamically set movieClip properties (like the x and y position on the stage)
  3. The instance name is used to target a movieClip

You never know, the ability to create a custom mouse pointer might be useful some day. Perhaps you can combine it with some other skills:

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

If you want to create a simple drawing application like the one above, replace your script with the script below. Experiment! You can alter the line color, thickness, and transparency using the lineStyle script:

init();
function init()
{
Mouse.hide();
attachMovie("pencil","pencil",1);
pencil._x = Stage.width/2;
pencil._y = Stage.height/2;
startDrag("pencil",true);
lineStyle(1,0xCC0000,100);
}
function onMouseDown():Void
{
moveTo(_xmouse,_ymouse);
onMouseMove = draw;
}
function onMouseUp():Void
{
delete onMouseMove
}
function draw():Void
{
lineTo(_xmouse,_ymouse);
}