That'll probably work (look okay, haven't tested though). However, there are some things you should consider:
- With that code, you're going to download the .mp3 file every time you click the menu item. I don't know what the purpose of your script is, but wouldn't it be better to download it only the first time to a known location and just play the local file every time it's called afterwards?
- More importantly: your script is responsible for the clean-up of the downloaded files. That means, if you download a file to a temporary location, Plus! won't delete it when the script terminates. When you don't clean up your temporary files, you'll end up with a big mess of files in your Temp directory.
Therefore, it would be better if you keep track of all downloaded files and schedule them for deletion on script termination:
js code:
// Global array to store downloaded files in
var arrDownloaded = [];
// On exit, loop through the array and remove all downloaded files
function OnEvent_Uninitialize() {
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var i = arrDownloaded.length;
while(i--) {
try { FSO.GetFile(arrDownloaded[i]).Delete(); } catch(e) { }
}
arrDownloaded = [];
}
// On download complete, add the file to the downloaded files array
function OnEvent_DownloadFileComplete(Url, OutFile, Success) {
Debug.Trace("DownloadFileComplete event received for " + Url);
Debug.Trace(" Success: " + Success);
if(Success) {
>>> arrDownloaded.push(OutFile);<<<
MsgPlus.PlaySound(OutFile);
}
}