0

我在这里有这个http://www.nzombie.eshost.es/带有自定义鼠标。它工作得很好,只是当它在另一个电影剪辑后面时它会“隐藏”自己。我不知道怎么了。任何建议或帮助将不胜感激。这是鼠标类:

package 
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.ui.Mouse;

public class myCursor extends MovieClip
{
    public function myCursor(stage):void
    {
        stop();
        Mouse.hide();
        stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
        stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
        stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
        addEventListener(Event.REMOVED_FROM_STAGE, onRemove);
    }
    private function updateCoor(e:MouseEvent):void
    {
        x = e.stageX;
        y = e.stageY;
        e.updateAfterEvent();
    }
    private function onDown(e:MouseEvent):void
    {
        updateCoor(e);
        gotoAndStop(2);
    }
    private function onUp(e:MouseEvent):void
    {
        updateCoor(e);
        gotoAndStop(1);
    }
    private function onMove(e:MouseEvent):void
    {
        Mouse.hide();
        updateCoor(e);
    }
    private function onRemove(e:Event):void
    {
        Mouse.show();
        stage.removeEventListener(MouseEvent.MOUSE_DOWN, onDown);
        stage.removeEventListener(MouseEvent.MOUSE_UP, onUp);
        stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
        removeEventListener(Event.REMOVED_FROM_STAGE, onRemove);
    }
}
}
4

2 回答 2

0

我相信问题不在于这个类,而在于你添加myCursor对象的类。

按钮可能已添加在光标之后,因此光标位于显示列表中的按钮后面。myCursor在将按钮添加到阶段后尝试添加。

于 2013-07-07T03:51:58.837 回答
0

如果您在运行时向舞台添加多个内容,则值得覆盖 addChild 以便将所有内容添加到索引 1,使光标(在索引 0 处)始终位于顶部。

像这样的东西:

override public function addChild(value:displayObject):void
{
    var index:uint = 1;
    if(value is myCursor){index = 0;}
    addChildAt(value, index);
}

或者只是使用 addChildAt(displayObject, 1) 添加新的显示对象,并确保将光标类添加到 0;

于 2013-07-07T21:17:26.610 回答