这是我的学校项目的一个类,但它现在不起作用。 http://pastebin.com/0K9H6wAi
我有一只青蛙眨眼3次而不是动作 - 到目前为止,非常好。 但是当它移动时它必须再次闪烁并再次移动,我无法弄清楚这一点。这发生在第109行直到结束。
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.geom.Point;
public class KikkerOgen extends MovieClip {
var timer:Timer = new Timer(1000, 4);
var geknipperd:int = 0;
var hoevaakKnipperen:int = 0;
var aantalGezwommen
var score:int = 0;
//boompjes en bosjes
var object_1:Point = new Point(57,84);
var object_2:Point = new Point(500,86);
var object_3:Point = new Point(46,168);
var object_4:Point = new Point(479,126);
var object_5:Point = new Point(69,159);
var object_6:Point = new Point(443,162);
var object_7:Point = new Point(248,316);
var object_8:Point = new Point(209,198);
var object_9:Point = new Point(163,357);
var object_10:Point = new Point(440,283);
//constructor
public function KikkerOgen()
{
addEventListener(Event.ENTER_FRAME, Update);
addEventListener(MouseEvent.CLICK, isClicked);
timer.addEventListener(TimerEvent.TIMER, Knipperen);
timer.start();
gotoAndStop(13);
}
public function Update (event:Event)
{
trace(currentFrame);
}
//Score moet bij deze functie omhoog - document class
public function isClicked (event:MouseEvent):void
{
this.parent.removeChild(this);
}
//Hier telt hij het aantal keren dat de kikker moet knipperen
function Knipperen (event:TimerEvent):void
{
if (event.currentTarget.currentCount >= 2 && geknipperd < 3) {
geknipperd ++;
gotoAndPlay(1);
}
//Wanneer de kikker 3x geknipperd heeft moet hij naar een nieuwe positie
if (geknipperd == 3)
{
//Selecteer een random positie om heen te zwemmen
switch(Math.round(Math.random() * 10))
{
case 1:
x = object_1.x;
y = object_1.y;
break;
case 2:
x = object_2.x;
y = object_2.y;
break;
case 3:
x = object_3.x;
y = object_3.y;
break;
case 4:
x = object_4.x;
y = object_4.y;
break;
case 5:
x = object_5.x;
y = object_5.y;
break;
case 6:
x = object_6.x;
y = object_6.y;
break;
case 7:
x = object_7.x;
y = object_7.y;
break;
case 8:
x = object_8.x;
y = object_8.y;
break;
case 9:
x = object_9.x;
y = object_9.y;
break;
case 10:
x = object_10.x;
y = object_10.y;
break;
}
trace("posX:"+x);
trace("posY:"+y);
//Reset de timmer, het knipperen en laat hem opnieuw tellen om te verplaatsen.
geknipperd = 0;
trace(geknipperd);
timer.reset();
aantalGezwommen ++;
}
}
//Wanneer de kikker 3x is verplaats verwijder hem uit het spel
function removeKikker ()
{
if (aantalGezwommen == 3)
{
this.parent.removeChild(this);
}
}
}
}
知道这里出了什么问题吗?
答案 0 :(得分:0)
你拨打timer.reset();
停止计时器但不再启动计时器。
Stops the timer, if it is running, and sets the currentCount property back to 0, like the reset button of a stopwatch.
重置计时器后,请务必使用timer.start();