我有一个功能,我需要点击和立方体一次,立方体将旋转到那一侧,然后当我点击并按住2秒将转到第五页或当我点击没有保持将启动立方体旋转
这就是我所拥有的
var numPressed:Number = 0
function side6(event:MouseEvent):void {
numPressed++;
if (numPressed % 2) {
SimpleZSorter.sortClips(container);
TweenLite.to(container, 1, {rotationX:-8,rotationY:193});
addEventListener(Event.ENTER_FRAME, rotateStop);
removeEventListener(Event.ENTER_FRAME, rotateThis);
}else if (NEED SOEMTHING HERE TO DETECT MOSUE HOLD AFTER SECONDS) {
gotoAndStop(5);
}
else{
addEventListener(Event.ENTER_FRAME, rotateThis);
}
}
如果按下奇数或偶数,意思是atump计算,意味着1次点击将停止立方体旋转,2将再次启动,第三次将停止,如果等等,我需要这样做以保持这样的行为。
我在第二个if语句中需要一些东西,除了让它在按住鼠标时工作正常。
任何帮助表示赞赏
伊恩
答案 0 :(得分:0)
我建议您使用MouseEvent.DOWN
和MouseEvent.UP
并存储Date.time
。
EG:这组函数将跟踪MouseEvent.DOWN和MouseEvent.UP事件之间经过的毫秒数。
private var mouseDownTime:Number = NaN,mouseUpTime:Number = NaN;
private function init():void
{
yourCubeObject.addEventListener(MouseEvent.DOWN,onMouseDown);
yourCubeObject.addEventListener(MouseEvent.UP,onMouseUp);
yourCubeObject.addEventListener(MouseEvent.OUT,onMouseOut);
}
private function onMouseOut(event:MouseEvent):void
{
mouseDownTime = mouseUpTime = NaN;//clear storage
}
private function onMouseDown(event:MouseEvent):void
{
mouseDownTime = new Date().time;//store system time in milliseconds since epoc
}
private function onMouseUp(event:MouseEvent):void
{
mouseUpTime = new Date().time;
if (!isNaN(mouseDownTime))//avoid error case where mouse went down outside object
{
if ((mouseUpTime - mouseDownTime) >= 2000)
{
//mouse held down for more the 2 seconds, your function here.
}
}
onMouseOut(event);//reset counters
}