Tuesday, July 7, 2009

How to make a custom cursor

I haven't made anything in awhile so I decided to make this tutorial on using custom cursors. Also this could be really easily made into a sniper game.

First of all draw your cursor then convert it into a symbol (F8) then select movieclip from the drop down box. After you do this double click your cursor and then you will be editing the movieclip. Once you're inside the movieclip, open up the align pallet by going to the top bar and Clicking Window > Align. Make sure "To stage:" is selected and select your cursor. Then use the align buttons to put the part of the cursor that you would like to click with at the Registration Point (The small + sign)

Double click anywhere on the stage to exit back the the main file. Select your cursor and make it's instance name "crs"







Next open up the Actions pallet and enter this code in the frame your cursor is in: stage.addEventListener(MouseEvent.MOUSE_MOVE, movecrs);
stage.addEventListener(Event.MOUSE_LEAVE, outahere);

function movecrs(e:MouseEvent):void {
crs.x = mouseX;
crs.y = mouseY;
crs.visible = true;
Mouse.hide();
crs.mouseEnabled = false;
crs.mouseChildren = false;
}

function outahere(e:Event):void {
Mouse.show();
crs.visible = false;
}


The first two lines tell Flash to "listen" for one event each. The first one says that when the mouse moves run the "movecrs" function. The next one says when the mouse leaves the screen run the "outahere" function. The next line opens the movecrs function. Then it sets the x and y position of the object you drew to the actual cursor. after that it makes sure your cursor is visible and then hides the actual mouse. The next two lines make sure that buttons work with your cursor. Then the "}" closes the function. next in the outahere function it says that when the mouse moves away from the Flash window it un-hides the real cursor and hides your cursor.

now hit control enter to test your cursor.