00:00
00:00
Newgrounds Background Image Theme

Rashioken just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Draw Your Own Cursor Inside The Swf

904 Views | 11 Replies
New Topic Respond to this Topic

In this text tut i will give you a very simple one-frame actionscript code to allow you to put a feature in your movies that lets the viewer draw and use their own cursor.
IMPORTANT: THE CUSTOM CURSOR WILL TAKE EFFECT AFTER THE MOUSE IS RELEASED FOR THE FIRST TIME, AND THE MOUSE POINT WILL BE THE LAST PLACE THE MOUSE WAS BEFORE IT WAS RELEASED!

Actionscript knowledge needed:

Basic function and drawing knowledge.

Okay to start off just select the first frame of your movie.

Type in the following actionscript. Afterwards, I will explain what it means, in case you don't understand it.

_root.createEmptyMovieClip("thing", 1);
thing.lineStyle(2, 0x000000, 100);
onMouseDown = function () {
thing.moveTo(_xmouse, _ymouse);
onMouseMove = function () { thing.lineTo(_xmouse, _ymouse);};
};
onMouseUp = function () {
Mouse.hide()
onMouseDown = null
onMouseMove = null
startDrag(_root.thing, false)
};

_root.createEmptyMovieClip("thing", 1); gives the command to create an empty movie clip named "thing" on the main stage, with a depth of 1. Depth doesn't matter unless you are creating more than one empty movie clip, in which case they will overlap eachother with the higher depths being higher.

thing.lineStyle(2, 0x000000, 100); Defines the thickness, color, and alpha value (transparency) of your cursor.

onMouseDown = function () { thing.moveTo(_xmouse, _ymouse); Says that when you click the mouse, the object point is going to move to where your mouse is. Without this code in the final product, you would just have the mouse being traced by line everywhere it went.

onMouseMove = function () { thing.lineTo(_xmouse, _ymouse);};
};
Says that, while the mouse is held down, when the mouse moves, a function takes place which tells the object point to make a line with the mouse point.

onMouseUp = function () {
Mouse.hide()
onMouseDown = null
onMouseMove = null
startDrag(_root.thing, false)
};
This says that when the mouse is released, a function takes place which hides the mouse and nullifies all other functions so that you can't draw any more, and it tells the mouse to start dragging the object drawn.

I suggest you have the FPS higher than 20 for this function, but it will still work otherwise.

So that's it. I hope this helps you in some insignificant way. if I made any little mistakes or left something out that you would like to know, just leave a review about it.

Response to Draw Your Own Cursor Inside The Swf 2006-01-01 18:13:51


Thats very nice. Why thank you.

Response to Draw Your Own Cursor Inside The Swf 2006-01-01 18:17:25


thats pretty easy, and also could be made better

Response to Draw Your Own Cursor Inside The Swf 2006-01-01 18:22:53


thats cool.. thanks !

Response to Draw Your Own Cursor Inside The Swf 2006-01-02 12:44:54


how do you make it so when you press a button, it changes the colour


BBS Signature

Response to Draw Your Own Cursor Inside The Swf 2006-01-02 12:53:34


At 1/2/06 12:44 PM, Hoeloe wrote: how do you make it so when you press a button, it changes the colour

You'll need to clear the API, change the line/fill style then redraw the shape.


Sup, bitches :)

BBS Signature

Response to Draw Your Own Cursor Inside The Swf 2006-01-02 13:01:30


how do you change the thickness in the same way?


BBS Signature

Response to Draw Your Own Cursor Inside The Swf 2006-01-02 13:08:45


At 1/2/06 01:01 PM, Hoeloe wrote: how do you change the thickness in the same way?

The same way.


Sup, bitches :)

BBS Signature

Response to Draw Your Own Cursor Inside The Swf 2006-01-02 13:23:16


that is prity cool but check out mine:

i = 1;
_root.createEmptyMovieClip("thing"+i, i);
_root["thing"+i].lineStyle(2, 0x000000, 100);
onMouseDown = function () {
with (_root["thing"+i]) {
beginFill(0xFFFFFF);
moveTo(_xmouse, _ymouse);
onMouseMove = function () { lineTo(_xmouse, _ymouse);};
}
};
onMouseUp = function () {
onMouseMove = null;
};

multiple odd looking shapes will appear

Response to Draw Your Own Cursor Inside The Swf 2006-01-02 14:24:28


sorry for all these questions, buthow do you make so that if, say you press a button, you can continue drawing the cursor from where you left off?


BBS Signature

Response to Draw Your Own Cursor Inside The Swf 2006-01-02 14:58:50


At 1/2/06 02:24 PM, Hoeloe wrote: sorry for all these questions, buthow do you make so that if, say you press a button, you can continue drawing the cursor from where you left off?

alright here is a final code. it doesnt automatically hide the mouse when you release it. when ur done, hit spacebar when ur mouse is at the point of your cursor.

_root.createEmptyMovieClip("thing", 1);
thing.lineStyle(2, 0x000000, 100);
onMouseDown = function () {
thing.moveTo(_xmouse, _ymouse);
onMouseMove = function () { thing.lineTo(_xmouse, _ymouse);};
};
onMouseUp = function () {
onMouseMove = null;
};
onEnterFrame = function () {
if (Key.isDown(Key.SPACE)) {
Mouse.hide();
startDrag(thing);
onMouseMove = null;
onMouseDown = null;
}
};

Response to Draw Your Own Cursor Inside The Swf 2006-01-07 08:19:02


that was helpful =)