我在阳光下尝试了一切,我无法弄清楚为什么我的计时器拒绝停止运行。如果有人能提供帮助,我将非常感激!鳕鱼如下:
package {
import flash.display.Stage;
import flash.display.MovieClip;
import flash.events.Event;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
public class Monster extends MovieClip
{
var X:int;
var Y:int;
var dodge:Boolean = false;
var myTween:Tween;
var myTimer:Timer = new Timer(1000,0);// 1 second
var alive:Boolean = true;
var gameWidth = Main.stage.stageWidth;
public function Monster(X:int, Y:int, whichMonster:Number):void
{
myTimer.addEventListener(TimerEvent.TIMER, dodgeAttack);
if ( whichMonster == 1 )
{
myTimer.start();
trace("Is it running "+myTimer.running);
level_1(X, Y);
}
else if ( whichMonster == 2 )
{
myTimer.stop();
removeEventListener(TimerEvent.TIMER,dodgeAttack);
trace("Is it still running "+myTimer.running);
level_2(X, Y);
}
else if ( whichMonster == 3 )
{
level_3(X, Y);
trace("Is it running "+myTimer.running);
myTimer.start();
}
else if ( whichMonster == 4 )
{
level_4(X, Y);
}
}
public function level_1(X:int, Y:int):int
{
this.x = X;
this.y = Y;
return X,Y;
}
public function level_2(X:int, Y:int):int
{
this.x = X;
this.y = Y;
//Just hardcode the tweens
myTween = new Tween(this,"x",Strong.easeOut,this.x,500,1,true);
myTween.addEventListener(TweenEvent.MOTION_FINISH, onFinish);
return X,Y;
}
public function level_3(X:int, Y:int):int
{
this.x = X;
this.y = Y;
return X,Y;
}
public function level_4(X:int, Y:int):int
{
this.x = X;
this.y = Y;
return X,Y;
}
function onFinish(e:TweenEvent):void
{
myTween.yoyo();
}
function dodgeAttack(e:TimerEvent):void
{
var deflect:int = Math.floor(Math.random() * 5);
if (deflect == 3)
{
this.gotoAndPlay(114);
}
else
{
trace("It Ran ");
}
}
任何帮助将不胜感激!谢谢!