动作脚本 3 中的计时器
我有一个问题,我需要创建计时器,但我想向它传递一个变量,该怎么做? AS3 中可以吗?
我尝试这样:
bonusPlayer1Timer = new Timer(5000);
bonusPlayer1Timer.addEventListener(TimerEvent.TIMER, bonusChanges(player1));
bonusPlayer1Timer.addEventListener(TimerEvent.TIMER_COMPLETE, bonusChangesRemove(player1));
bonusPlayer1Timer.start();
function bonusChanges(event:TimerEvent, playerBonus:Player):void {
switch (playerBonus.bonus) {
case 0 :
playerBonus.multipleShooting = false;
playerBonus.bonus = -1;
break;
...}}
但是我有错误:
1067: Implicit coercion of a value of type Player to an unrelated type flash.events:TimerEvent.
1136: Incorrect number of arguments. Expected 2.
并且这个错误在粗体行中。
我可以这样使用它吗?或者我必须为每个玩家创建两个相同的函数,因为我不允许将任何不同的参数传递给计时器函数?
谢谢你,
I have problem that I need to create timer but I want to pass on a variable to it, how to do it? Is it possible in AS3?
I tried like this:
bonusPlayer1Timer = new Timer(5000);
bonusPlayer1Timer.addEventListener(TimerEvent.TIMER, bonusChanges(player1));
bonusPlayer1Timer.addEventListener(TimerEvent.TIMER_COMPLETE, bonusChangesRemove(player1));
bonusPlayer1Timer.start();
function bonusChanges(event:TimerEvent, playerBonus:Player):void {
switch (playerBonus.bonus) {
case 0 :
playerBonus.multipleShooting = false;
playerBonus.bonus = -1;
break;
...}}
But I have error:
1067: Implicit coercion of a value of type Player to an unrelated type flash.events:TimerEvent.
1136: Incorrect number of arguments. Expected 2.
And this error is in the bold line.
Can I use it in this way? Or I have to create two the same function for every of my players because I am not allow to pass on any different arguments to the timer function?
Thank you,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
创建一个扩展 Timer 类的类并为 Player 添加一个属性。
使用您的示例,代码将如下所示:
Create a class that extends the Timer class and add a property for the Player.
Using your example the code would be something like this:
您永远不能将多个参数传递到由EventListener 触发的函数中。您需要找到其他方式来传递信息,例如 Nathan Smith 提供的解决方案。
You can never pass more than one argument into the function triggered by an EventListener. You need to find other ways of passing your information around, such as the solution provided by Nathan Smith.
你也可以这样做:
you can also do it this way:
只需输入
var BonusPlayer1Timer = new Timer(5000);
Just Type
var bonusPlayer1Timer = new Timer(5000);