- Home /
Question by
dansav · Mar 13, 2012 at 07:38 PM ·
c#javascriptfunctionaction
javascript equivalent of Action?
I'm trying to port some code from the audiorecorder plugin from prime31 from c# to javascript. The Author at Prime31 wasn't sure. I don't understand these lines that include ACTION. I looked up action but still don't know what would be a javascript equivalent. It looks like ACTION is defining some sort of function and putting it into a variable? I thought unityscript javascript could not do that sort of thing. Can someone help me find a javascript equivalent to these Action lines below.
var onFailure = new Action<string>( error => Debug.Log( error ) );
var onSuccess = new Action<AudioClip>( clip =>
{
audio.clip = clip;
audio.Play();
});
StartCoroutine( AudioRecorderBinding.loadAudioFileAtPath( file, onFailure, onSuccess ) );
Other relevant code:
function onError( error:String)
{
display="error loading audio file: " + error ;
}
function onSuccess( clip:AudioClip )
{
audio.clip = clip;
audio.Play();
}
public static IEnumerator loadAudioFileAtPath( string file, Action<string> onFailure, Action<AudioClip> onSuccess )
{
var www = new WWW( file );
yield return www;
if( www.error != null )
{
if( onFailure != null )
onFailure( www.error );
}
if( www.audioClip )
{
if( onSuccess != null )
onSuccess( www.GetAudioClip( false ) );
}
www.Dispose();
}
Comment
Your answer
Follow this Question
Related Questions
What should i learn for unity C# or UnityScript? 4 Answers
What programming language do I need to learn? 0 Answers
Multiple Cars not working 1 Answer