我有两个类,一个带有循环,另一个带有定时器,我正在尝试将数据从定时器发送到循环。
以下是Main.as的相关部分:
var zero:int = 0;
var shoot:Shooting = new Shooting(zero); //send zero to class Shooting
while (shoot.finished == 0)
{
move.data; //here data to move an object, rest is irrelevant...
}
与Shooting.as相关:
public class Shooting extends Sprite
{
private var twenty:int;
private var remove:int;
public var _isPassed:int = 0;
private var thedata:int;
public var finished:int = 0;
public function Shooting(data:int):void
{
thedata = data; // store the zero
var updateTimer:Timer;
updateTimer = new Timer(1, 30);
updateTimer.addEventListener(TimerEvent.TIMER, Fire);
updateTimer.start();
}
public function Fire(e:TimerEvent):void
{
for(var i:int=thedata; i >= 0; i--){ // data is bigger or = to 0 so keep going
if (_isPassed == 29)
{
finished = 1;
_isPassed = 0;
//do more stuff and break
break;
}
// it will go here if it's not the 29 time and do +1 to ispassed.
_isPassed += 1;
var atwenty:int = 20;
twenty = atwenty;
break;
}
}
所以,在Main.class中,有一个"而#34;检查是否完成== 0(默认情况下是),如果是,它将移动一个对象。在Shooting.as中,有一个计时器正在进行中 30次,并且在第29次它应该停止自己(它确实如此),并将完成的var更改为1.问题是,虽然没有检测到" 1"它继续移动该对象,我的闪光灯崩溃。我正在寻找一种更好的方式来在计时器和课程之间进行交流,并找出我做错了什么。
谢谢。