我建立一个依靠通过在命中区域重复mouse_down
来获得积分的游戏,但我希望玩家只有在hit
是pressing
的情况下才能获得积分活性。如果我没有收到语法错误,则不会发生任何事情。我知道代码错了。
我需要onPressing
才能使onPressing
成为真,然后触发noot
,然后,
mouse_over
将var score:int = 0
score = 0;
var pressing:Boolean = false;
hit.addEventListener(MouseEvent.MOUSE_DOWN, maketrue);
function maketrue(evt:Event){
pressing = true;
trace("honk");
onPressing();
}
}
function onPressing(evt:Event){
if (pressing==true){
noot();
}
}
function noot(event:MouseEvent = null)// this should be mouse_over, gain points
{
score++;
trace("Moused over");
trace("Score: " + score);
}
作为app.post('/doneList/:id',function(req, res){
var id = mongojs.ObjectId(req.params.id);
var oneTodo;
db.todoList.findAndModify(
{
"query": { "_id": id },
"remove": true
},
function(err,doc) {
if (doc) {
db.doneList.insert(doc,function(err,doc){
// respond moved
});
} else {
// respond was not found
}
);
触发,每个mouse_over都会记录一个得分点并跟踪它。
.insert()
答案 0 :(得分:1)
要仅在触发另一个事件时才有事件,您需要一个简单的设置:
// In this example mouseOver event will only activate when mouseDown event has fired
// for the sake of simplicity this has been done in a frame, not in a class
import flash.display.Sprite;
import flash.events.MouseEvent;
var mySprite:Sprite = new Sprite(); // we'll use this as a button
mySprite.graphics.beginFill( 0xFF0000, 1);
mySprite.graphics.drawCircle( 0, 0, 50 );
mySprite.graphics.endFill();
mySprite.x = 50;
mySprite.y = 50;
mySprite.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
addChild(mySprite);
var myMouseOverSprite:Sprite = new Sprite(); // this sprite will be used to roll over the mouse on
myMouseOverSprite.graphics.beginFill(0x00FF00, 1);
myMouseOverSprite.graphics.drawCircle( 0, 0, 70 );
myMouseOverSprite.graphics.endFill();
myMouseOverSprite.x = 150;
myMouseOverSprite.y = 150;
addChild(myMouseOverSprite);
function onMouseDownHandler(e:MouseEvent):void
{
trace("mouse is down on mySprite");
myMouseOverSprite.addEventListener(MouseEvent.ROLL_OVER, onMouseRollOverHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, onStageMouseUpHandler); // this is important so we don't have roll over firing after mouse is up
}
function onStageMouseUpHandler(e:MouseEvent):void
{
myMouseOverSprite.graphics.clear();
myMouseOverSprite.graphics.beginFill( 0x00FF00, 1); // return sprite to original color
myMouseOverSprite.graphics.drawCircle( 0, 0, 70 );
myMouseOverSprite.graphics.endFill();
myMouseOverSprite.removeEventListener(MouseEvent.ROLL_OVER, onMouseRollOverHandler);
}
function onMouseRollOverHandler(e:MouseEvent):void
{
trace("mouse is rolling over myMouseOverSprite");
myMouseOverSprite.graphics.clear();
myMouseOverSprite.graphics.beginFill( Math.random() * int.MAX_VALUE >> 0, 1); // change sprite to a random color
myMouseOverSprite.graphics.drawCircle( 0, 0, 70 );
myMouseOverSprite.graphics.endFill();
}
在此示例中,您将看到两个圆圈。红色是一个按钮 - 当您按下它时,绿色圆圈将准备好接收ROLL_OVER事件。当你让鼠标再次上升时,绿色圆圈将返回到它的开始状态。
答案 1 :(得分:1)
一些事情:
修复这些问题后,每次单击匹配符号时,跟踪都会起作用,并且分数会递增。
但是,为了达到你描述的效果,当用户按下鼠标按钮时鼠标悬停在命中区域上时,用户反复得分,我建议不要使用"鼠标悬停"。这是因为鼠标悬停只会在鼠标实际移动时触发。当用户在命中区域顶部滚动并停止时,它将不会触发Mouse Over事件。
我建议进行以下调整:
var score:int = 0
score = 0;
var pressing:Boolean = false;
//stage listens for mouse down
stage.addEventListener(MouseEvent.MOUSE_DOWN, maketrue);
function maketrue(evt:Event){
pressing = true;
trace("honk");
}
//stage listens for mouse up
stage.addEventListener(MouseEvent.MOUSE_UP, makefalse);
function makefalse(evt:Event){
pressing = false;
trace("unhonk");
}
hit.addEventListener(Event.ENTER_FRAME, checkCollision);
function checkCollision(evt:Event):void{
//pseudocode
/*
if(hitting cursor) && pressing){
score++;
trace("Score: " + score);
}
*/
}