我要点一下,然后单击带有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”)。
非常感谢您的帮助!
如果您的库中有“ handCursor”,则需要为其分配一个类,例如“ HandCursor”。我建议类以大写字母开头。
因此,您的代码将需要为其创建一个新实例,然后对其进行显示,例如
var handCursor:HandCursor = new HandCursor; handCursor.visible = false;
handCursor.visible = false;
使它不可见,然后使其可见,您将:
handCursor.visible = true;
另外,如果将handCursor放在函数中,则它是一个局部变量,要使其在所有函数中全局使用,您需要将其放在类的开头。
另外,您遇到任何错误吗?如果是这样,请分享。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句