how to match as3 function type declaration with differing calls?
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 functi开发者_开发问答on 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!
Use a default parameter:
public function nextTrack(evt:Event = null):void {
It can then be called with or without the caller supplying a parameter.
精彩评论