package {
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.ui.Mouse;
import flash.events.Event;
public class CustomMouseCursor extends Sprite {
private var stageSprite;
private var cursor:CustomCursor;
private var gutter:uint = 10;
public function CustomMouseCursor() {
stageSprite = new Sprite();
addChild ( stageSprite );
stageSprite.width = stage.stageWidth;
stageSprite.height = stage.stageHeight;
stageSprite.addEventListener(Event.ENTER_FRAME, mouseOverHandler);
cursor = new CustomCursor();
addChild(cursor);
}
private function mouseOverHandler(e:Event):void {
Mouse.hide();
stageSprite.addEventListener(Event.ENTER_FRAME, mouseMoveHandler);
}
private function mouseOutHandler(e:Event):void {
Mouse.show();
stageSprite.removeEventListener(Event.ENTER_FRAME, mouseMoveHandler);
cursor.visible = false;
}
private function mouseMoveHandler(e:Event):void {
cursor.x = mouseX;
cursor.y = mouseY;
cursor.visible = true;
}
}
}
import flash.display.Shape;
class CustomCursor extends Shape {
var bgColor:uint = 0x336699;
var size:uint = 10;
public function CustomCursor() {
visible = false;
draw();
}
private function draw():void {
graphics.clear();
graphics.beginFill(bgColor);
graphics.drawRect(0, 0, size, size);
graphics.endFill();
}
}
Posted in Actionscript 3 .
By admin
– May 23, 2008
It seems like every time I google an AS problem, your site comes up and has the solution I need. I remember your picture up in the corner and every time I say “Damn dude, you saved my butt again.”
Glad to hear these little movies are able to help out!
Morgan
but why use shape for that? is it faster than just moving sprite around?
isn’t there a short code with the same results..??