dimani4
27.11.2009, 01:42
Всем привет.Хочу менять курсор мыши при наведении на свой прямоугольник. Проблема в том, что подставляемый вместо курсора, клип появляется не на месте курсора, и иногда еще возникает мигание.
Вот код.
private function createRegionForRotation() {
var rect:Sprite = new Sprite();
rect.graphics.beginFill(eColour);
rect.graphics.drawRect(0, 0, eWidth/3, eHeight);
rect.graphics.endFill();
rect.addEventListener(MouseEvent.MOUSE_OVER, showCursor);
rect.addEventListener(MouseEvent.MOUSE_OUT, hideCursor);
return rect;
}
private function showCursor(event:MouseEvent) {
if (event.target is Sprite) {
var m:Point = new Point(mouseX, mouseY)
m = localToGlobal(m);
m = parent.globalToLocal(m);
if (!this.cfRotation) {
this.rotatedNow = 1; // init
Mouse.hide();
this.cfRotation = new CursorForRotation();
this.cfRotation.gotoAndStop(1);
this.cfRotation.x = m.x;
this.cfRotation.Y = m.y;
trace(m.y);
parent.addChild(this.cfRotation);
}
//this.rx = stage.mouseX;
//this.ry = stage.mouseY;
//this.cfRotation.x = m.x;
//this.cfRotation.Y = m.y;
//event.updateAfterEvent();
this.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
}
}
private function onMove(event:MouseEvent) {
/* if (this.rotatedNow>0) { // поварачиваем
this.rotatedNow = 2; // start rotate
//event.updateAfterEvent();
}
*/
if (this.cfRotation) {
var m:Point = new Point(mouseX, mouseY);
m = localToGlobal(m);
m = parent.globalToLocal(m);
this.cfRotation.x = m.x;
this.cfRotation.Y = m.y;
}
}
private function hideCursor(event:MouseEvent) {
if (event.target is Sprite) {
if (this.rotatedNow != 2) {
this.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
this.rotatedNow = 0;
parent.removeChild(this.cfRotation);
this.cfRotation = null;
Mouse.show();
}
}
}
Добавлено через 23 часа 29 минут
Всем спасибо за помощь. Ошибки идиотские. Вместо this.cfRotation.Y = m.y; надо this.cfRotation.y = m.y;(обратите внимание на y). И для того чтобы мовик плавно ходил за мышкой для курсора нужен startDrag.
Вот код.
private function createRegionForRotation() {
var rect:Sprite = new Sprite();
rect.graphics.beginFill(eColour);
rect.graphics.drawRect(0, 0, eWidth/3, eHeight);
rect.graphics.endFill();
rect.addEventListener(MouseEvent.MOUSE_OVER, showCursor);
rect.addEventListener(MouseEvent.MOUSE_OUT, hideCursor);
return rect;
}
private function showCursor(event:MouseEvent) {
if (event.target is Sprite) {
var m:Point = new Point(mouseX, mouseY)
m = localToGlobal(m);
m = parent.globalToLocal(m);
if (!this.cfRotation) {
this.rotatedNow = 1; // init
Mouse.hide();
this.cfRotation = new CursorForRotation();
this.cfRotation.gotoAndStop(1);
this.cfRotation.x = m.x;
this.cfRotation.Y = m.y;
trace(m.y);
parent.addChild(this.cfRotation);
}
//this.rx = stage.mouseX;
//this.ry = stage.mouseY;
//this.cfRotation.x = m.x;
//this.cfRotation.Y = m.y;
//event.updateAfterEvent();
this.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
}
}
private function onMove(event:MouseEvent) {
/* if (this.rotatedNow>0) { // поварачиваем
this.rotatedNow = 2; // start rotate
//event.updateAfterEvent();
}
*/
if (this.cfRotation) {
var m:Point = new Point(mouseX, mouseY);
m = localToGlobal(m);
m = parent.globalToLocal(m);
this.cfRotation.x = m.x;
this.cfRotation.Y = m.y;
}
}
private function hideCursor(event:MouseEvent) {
if (event.target is Sprite) {
if (this.rotatedNow != 2) {
this.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
this.rotatedNow = 0;
parent.removeChild(this.cfRotation);
this.cfRotation = null;
Mouse.show();
}
}
}
Добавлено через 23 часа 29 минут
Всем спасибо за помощь. Ошибки идиотские. Вместо this.cfRotation.Y = m.y; надо this.cfRotation.y = m.y;(обратите внимание на y). И для того чтобы мовик плавно ходил за мышкой для курсора нужен startDrag.