【问题标题】:How to change cursor on Roll Over event如何在翻转事件上更改光标
【发布时间】:2013-10-14 01:13:34
【问题描述】:

我正在用 Flash 在 AS3 中制作一个点击游戏。

我通过创建一个新类“Souris”更改了光标的外观。它工作得很好。现在我正在尝试更改光标在场景中的对象上时的皮肤。

我读到 MouseEvent.ROLL_OVER 是个好方法,但我不知道该怎么做...

我的 Souris 课是这样的:

    public class Souris extends MovieClip
    {
 private var engine:Engine;
        private var stageRef:Stage;
        private var p:Point = new Point(); 

        public function Souris(stageRef:Stage)
        {
            Mouse.hide(); //make the mouse disappear
            mouseEnabled = false; //don't let our cursor block anything
mouseChildren = false;

            this.stageRef = stageRef;
            x = stageRef.mouseX;
            y = stageRef.mouseY;

            stageRef.addEventListener(MouseEvent.MOUSE_MOVE, updateMouse, false, 0, true);
            stageRef.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler, false, 0, true);
            stageRef.addEventListener(Event.ADDED, updateStack, false, 0, true);
            stageRef.addEventListener(MouseEvent.ROLL_OVER,hover);

        }

        private function updateStack(e:Event) : void
        {
            stageRef.addChild(this);
        }
        private function hover(e:MouseEvent):void {
               souris.visible = false;
            }

        private function mouseLeaveHandler(e:Event) : void
        {
            visible = false;
            Mouse.show(); //in case of right click
            stageRef.addEventListener(MouseEvent.MOUSE_MOVE, mouseReturnHandler,    false, 0, true);
        }

        private function mouseReturnHandler(e:Event) : void
        {
            visible = true;
            Mouse.hide(); //in case of right click
            removeEventListener(MouseEvent.MOUSE_MOVE, mouseReturnHandler);
        }

        private function updateMouse(e:MouseEvent) : void
        {
            x = stageRef.mouseX;
            y = stageRef.mouseY;

            e.updateAfterEvent();
        }

    }

}
}

在我的主课(引擎课)中,我有:

private var souris:Souris;

public function Engine(){



                        souris = new Souris(stage);
            stage.addChild(souris);

        }
private function startGame(e:Event):void{
....
..

我尝试加入“Souris”类

stageRef.addEventListener(MouseEvent.ROLL_OVER,hover);

private function hover(e:MouseEvent):void {
Engine.souris.visible = false; 
handCursor.visible = true ;
}

但这似乎是错误的...... 我不知道在悬停功能中放什么。 (我的库中有“handCursor”)。

非常感谢您的帮助!

【问题讨论】:

    标签: actionscript-3


    【解决方案1】:

    如果您的库中有“handCursor”,那么您需要为其分配一个类,例如“HandCursor”。我建议类以大写字母开头。

    所以你的代码需要创建它的一个新实例然后显示它,比如

    var handCursor:HandCursor = new HandCursor; handCursor.visible = false;
    

    handCursor.visible = false; 使其不可见,然后要使其可见,您可以:

    handCursor.visible = true;
    

    另外,handCursor 是一个局部变量,如果放在一个函数中,为了使它在所有函数中都可以全局使用,你需要把它放在你的类的开头。

    另外,您是否遇到任何错误?如果有,请分享。

    【讨论】:

    • 没有错误,但是当我将光标放在一个项目上时,我的手形光标没有出现...你知道为什么吗?我认为这是因为在我的 Engine 类中,我有 souris.visible = true (我已将您的代码放在“Souris”类中)
    • 不,我认为是 MouseEvent.ROLL_OVER 不起作用...也许它不是我必须放置的翻转...不?
    • @user2421975 很高兴听到这个消息,但下次请考虑“跟踪”声明。
    猜你喜欢
    • 2015-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 2018-06-10
    • 1970-01-01
    • 1970-01-01
    • 2011-12-23
    相关资源
    最近更新 更多