Mouse Over in whole Stage?

人盡茶涼 提交于 2020-01-06 17:14:22

问题


I want to run an Actionscript function when a user has his mouse in my flash stage. Not in a specific button/image on the stage but just in the stage. But when trying to use mouse over action on stage i get this message: "This action requires an object to be selected on stage."

So, how can i use mouse over in the whole stage?


回答1:


In AS3 there's an event for when mouse leaves the stage so you could do something like this to get if the users mouse is in the stage.

var _mouseOnStage : Boolean = true;

stage.addEventListener(MouseEvent.MOUSE_LEAVE, onMouseLeave);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);

function onMouseLeave(e:MouseEvent) : void {
    _mouseOnStage = false;
}

function onMouseMove(e:MouseEvent):void{
    _mouseOnStage = true;
}




回答2:


You need to have something that can be clicked, like some graphics drawing.

If you fill the stage with a rectangle of the same size, then add an event listener to the Stage, it should recognise it.



来源:https://stackoverflow.com/questions/5679052/mouse-over-in-whole-stage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!