You don't have to
call the OnEvent_DownloadFileComplete event, you have to
define that function!
Basically, Plus! acts like this:
- When you call DownloadFile with a code like this:
code:
var DownloadStarted = MsgPlus.DownloadFile("http://www.mysite.com/myscript.plsc", MsgPlus.ScriptFilesPath + "\\MyScript.plsc");
Plus! will start the download. Meanwhile, your script will continue, it will not wait until the download is finished to start executing the code again. This asynchronous behaviour prevents Messenger from freezing while the file is being downloaded.
- When the download is done, Plus! will look in your script files for an OnEvent_DownloadFileComplete function definition. It'll then call that function with the parameters of the download: the URL it was downloaded from, the file path it was saved to and a boolean indicating if the download was successful. You can use these given parameters in your function definition to do stuff with it, like moving or opening the downloaded file:
code:
function OnEvent_DownloadFileComplete(Url, OutFile, Success) {
if(Url == "http://www.mysite.com/myscript.plsc") {
if(Success) {
//The download of myscript.plsc was succesful.
//You can now use the OutFile variable to do something with your downloaded file.
Debug.Trace("Downloaded file saved in: "+OutFile);
} else {
//Uh-oh, the download failed!
//You can add in some error-handling here, to notify the user what has happened.
Debug.Trace("The download failed!");
}
}
}
Note that you can have only
one OnEvent_DownloadFileComplete function in your script, so if you have to download multiple files, you'll have to add another check in the function for that Url. I'm sure you'll figure that out if you ever need it.