Reputation: 23
I'm relatively new to Flash CS6, and I'm trying to make a custom cursor in a MS Paint clone I'm making. I want the cursor to turn right when I move the mouse to the right and vice versa.
My actionscript looks like this:
Mouse.hide()
mcGeit.stop()
var x_k:Array = Array();
stage.addEventListener(MouseEvent.MOUSE_MOVE, flyttMus);
function flyttMus(evt:MouseEvent)
{
mcGeit.x = mouseX;
mcGeit.y = mouseY;
var i:int
for(i = 0; i<100; i++)
{
x_k[i] = int(mouseX);
if (x_k[i] < x_k[i-10])
{
mcGeit.gotoAndStop(1);
}
else if (x_k[i] > x_k[i-10])
{
mcGeit.gotoAndStop(2);
}
}
}
I don't see what the error is, and when I start the file, everything flashes rapidly.
Upvotes: 0
Views: 441
Reputation: 888
If you want best responsiveness from the mouse cursor and avoid many problems (like double cursor/no cursor at all, having to handle out of screen/back to screen ..), you should use additional methods of Mouse
class which allows you to customize the mouse cursor at the OS level.
It will require a bit more work though, since it's bitmap based
mcGeit.getBounds()
and bitmapData.draw(mcGeit,...)
Mouse.registerCursor(...);
You should do it only once per cursor, as long as you dont' unregister the cursors.mcGeit.gotoAndStop(...);
call Mouse.cursor = ...;
with a registered cursor nameMouse.cursor = "auto";
will restore the default cursor.You can easily find tutos or resources about using native cursors
Keep in mind that it's not supported on very old platform (Flash Player < 10.2, AIR < 1.5) or mobile/tablets so if you relly need to support these cases, there is an example of how to detect the mouse cursor capability : Optionally use Flash 10.2 cursors, while still being compatible with Flash 10.0?
Upvotes: 1
Reputation: 159
Firstly var x_k:Array = Array(); must be var x_k:Array = new Array();
Mouse.hide()
mcGeit.stop()
var temp:Number = 0;
stage.addEventListener(MouseEvent.MOUSE_MOVE, flyttMus);
function flyttMus(evt:MouseEvent) {
mcGeit.x = mouseX;
if(mouseX < temp){
mcGeit.gotoAndStop(1);
}else{
mcGeit.gotoAndStop(2);
}
mcGeit.x = mouseX;
mcGeit.y = mouseY;
temp = mouseX;
}
I edit your code like this.
Upvotes: 0