如何将as3函数类型声明与不同的调用相匹配?
private function playSound():void
{
_soundChannel = _soundObj.play();
_soundChannel.addEventListener(Event.SOUND_COMPLETE, nextTrack);
}
<s:Button width="35" label=">>" click="nextTrack();"/>
假设 nextSound() 函数在类型上看起来与 playSound 相同...按钮单击工作正常,但事件侦听器不会调用该函数,因为它发送了该函数不期望的参数。 我可以将 nextTrack 函数更改为 evt:Event,但是按钮发送的参数不足,而且我找不到任何可以输入的内容。我可以创建一个类型化函数来从事件监听器调用非类型化 nextTrack 函数
public function callnextsong(evt:Event):void{
nextTrack();
}
,但我觉得可能有一种不太迂回的方法来完成它!
private function playSound():void
{
_soundChannel = _soundObj.play();
_soundChannel.addEventListener(Event.SOUND_COMPLETE, nextTrack);
}
<s:Button width="35" label=">>" click="nextTrack();"/>
Assuming the nextSound() function looks the same as playSound, typewise... The button click works fine, but the event listener won't call the function because its sending an argument the function isn't expecting.
I can change the nextTrack function to be evt:Event, but then the button is sending not enough arguments, and I can't find anything to type it to that will work. I can make a typed function to call the un-typed nextTrack function from the event listener
public function callnextsong(evt:Event):void{
nextTrack();
}
But i feel like there's probably a less circuitous way of accomplishing it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用默认参数:
无论调用者是否提供参数,都可以调用它。
Use a default parameter:
It can then be called with or without the caller supplying a parameter.