简体   繁体   中英

Calling function that expect an event AS3

Thank you for taking the time to read my question! So I have a function in my code that gets called after a TimerEvent. Like this:

shootTimer.addEventListener(TimerEvent.TIMER, shoot, false, 0, true);
private function shoot(e:Event):void

there is no problem with that, but what if I want to call the function shoot for something else too. like let's say

if(speed > 5)
shoot();

it doesn't work like that, can someone please explain me how to do it? Thank you a lot, in advance.

您可以为参数设置默认值,因此可以在没有事件的情况下调用它:

private function shoot(e:Event = null):void

You could do something like this

shootTimer.addEventListener(TimerEvent.TIMER, shoot, false, 0, true);

private function shoot(e:Event):void
{
realShoot();
}


if(speed > 5)
{
realShoot();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM