Mouse Over in whole Stage?

2019-08-24 08:54发布

问题:

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.