Posted by angela in SWF Studio V3 on May 16 2008, 01:20 pm

Hi,

I've been searching but I haven't been able to find the code to check if Adobe Reader is installed on the machine after invoking the command which opens the pdf, and if it is not, to display a prompt window with a message.

Thanks in advanced.
Angela


Posted by mbd in SWF Studio V3 on May 16 2008, 01:59 pm

You would check that before trying to open the PDF. Use ssCore.Shell.getDefaultApplication.

You will either get a path to the application that is registered for the extension, or an error saying there is no application associated with the extension.

If you just want to know if it's safe to launch the PDF you can just check the success property of the return object.


Posted by angela in SWF Studio V3 on May 17 2008, 04:52 am

Thanks for your answer though I haven't a lot of skills writing the code. I've found the code would be:

ssCore.Shell.getDefaultApplication( paramsObject [, callbackParamsObject] [, errorParamsObject] );

I know what to write in the first paramsObject but what's in callbackParamsObject and errorParamsObject ?

ssCore.Shell.getDefaultApplication( {extension:"pdf"} [, callbackParamsObject] [, errorParamsObject] );

Thanks a lot,
Angela


Posted by northcode in SWF Studio V3 on May 17 2008, 06:02 pm

The callback parameters object is used to specify the callback function for asynchronous commands and it's optional.

The error parameters object is used in asynchronous commands to specify the error callback function, it is also optional.

Check out the documentation for the ActionScript API for general help with the API that applies to all commands.

The code in the example for Shell.getDefaultApplication shows how you would test to see if an application had been registered to handle the PDF file format. Please note that this does not necessarily mean that Adobe Acrobat Reader has been installed, any applicatoin could hijack the PDF extension.

If you need to test specifically for the existence of the Adobe Acrobat Reader, the best solution is a quick check of the registry for the version you're looking for. This little example shows how to check for version 8.0 of the Acrobat Reader.

var r = ssCore.Registry.getValue({rootKey:"HKEY_LOCAL_MACHINE", subKey:"SOFTWARE\\Adobe\\Acrobat Reader\\8.0\\InstallPath"});
if (r.result != undefined && r.result != "")
ssDebug.trace("Acrobat is installed at: " + r.result);


Posted by angela in SWF Studio V3 on May 19 2008, 04:34 am

Thanks Tim,

The code I'm looking for is:

1. To check if there is any Acrobar Reader installed in the user's machine. If it exists, the pdf will be launched.

2. But if it is not, there should appear a message box saying that Acrobat Reader is not installed. The user should install the Acrobat we include in the cd.

Sorry to bother you with these things.

Thanks again.


Posted by northcode in SWF Studio V3 on May 20 2008, 04:05 am

Does it have to be Adobe Acrobat Reader or do you just want to make sure that when you launch the PDF that it will open? If that's all, then Shell.getDefaultApplication will tell you whether the PDF can be opened or not. If it's not there, then you can start the Adobe Acrobat Reader installation. The code for that might look something like this...


var r = ssCore.Shell.getDefaultApplication({extension:"pdf"});

if (r.result != undefined && r.result != "")
{
   // a PDF viewer is installed, open the PDF
   ssCore.Shell.open({path:"startdir://thefile.pdf"});
}
else
{
   // run the Adobe Acrobat Reader setup 
   ssCore.Shell.execute({path:"startdir://setup.exe})
}


Posted by angela in SWF Studio V3 on May 20 2008, 01:43 pm

Yes, yes, yes! To me this is perfect. Instead of the last line I've written:

else
{
ssCoreShell.App.showMsgBox ({prompt: "The message"});
}

to tell the user that Acrobat Reader is not installed in the computer (I have another button to start the installation of Acro using the last line of your code).

You are all so helpful, thanks sooo much!

Angela

PS. Let's see what my client says...


Posted by angela in SWF Studio V3 on Jun 09 2008, 07:00 am

Hello again,

I have a little problem. When I write this code:

ssCore.Shell.open({path:"startdir://thefile.pdf"});

everything works fine, but if I use this one:

ssCore.Shell.open({path:"startdir://folder/thefile.pdf"}); or

ssCore.Shell.open({path:"startdir://folder\\thefile.pdf"});

it doesn't. Any clue?

Thanks so much,
Angela


Posted by angela in SWF Studio V3 on Jun 09 2008, 07:10 am

Hey,

I've just solved the problem, it was the \ instead of \\:

ssCore.Shell.open({path:"startdir://folder\thefile.pdf"});

;)


Posted by angela in SWF Studio V3 on Jun 09 2008, 07:22 am

Sorry, it's me again. It worked the first time but no the rest of the trials, I can't understand it...


Posted by northcode in SWF Studio V3 on Jun 09 2008, 08:06 am

What, specifically, isn't working? The reader detection via Shell.getDefaultApplication? The call to Shell.open?


Posted by angela in SWF Studio V3 on Jun 09 2008, 08:29 am

I think it's the Shell.open

I had told you it worked but I was wrong, it worked with .invoke not with .open


Posted by pompeyd in SWF Studio V3 on Jun 09 2008, 08:32 am


QUOTE: from angela;44581
Hey,

I've just solved the problem, it was the \ instead of \\:

ssCore.Shell.open({path:"startdir://folder\thefile.pdf"});

;)


Hi Angela,

\ instead of \\ won't work because it is a special escape character. If you trace out your path with just \ you will see what happens.

I've just tested and getDefaultApplication works fine along with Shell.open. Can you post an example of this failing, otherwise it is just guess work.

Regards

Paul


Posted by angela in SWF Studio V3 on Jun 09 2008, 08:34 am

This is the code I'm using:

on (release) {
var r = ssCore.Shell.getDefaultApplication({extension:"pdf"});

if (r.result != undefined && r.result != "") {

ssCore.Shell.open({path:"startdir://Folder/thefile.pdf"});

} else {

ssCore.App.showMsgBox({prompt:"The Message"});

}
}


Posted by pompeyd in SWF Studio V3 on Jun 09 2008, 08:38 am

First off change / between Folder and your file to \\.

/ is not guaranteed to work in a windows path - while \\ is.


Posted by angela in SWF Studio V3 on Jun 09 2008, 08:48 am

Hi pompeyd,

I already made that change and it didn't work for me. I have acrobat reader installed on my pc and it shows me the message of the prompt window where I wrote : "Acrobat Reader is not installed" (but it is).


Posted by angela in SWF Studio V3 on Jun 09 2008, 11:00 am

This code doesn't work either, it doesn' open the pdf:

on (release) {

ssCore.Shell.open({path:"startdir://thefile.pdf"});

}


Posted by northcode in SWF Studio V3 on Jun 09 2008, 11:43 am

ssCore.Shell.open({path:"startdir://thefile.pdf"}) will only work if the PDF is in the same folder as your application.

If you're seeing the message that says the reader is not installed then you have more basic problems, the detection isn't working.


Posted by angela in SWF Studio V3 on Jun 09 2008, 01:57 pm

Yes, the pdf is in the same folder, but it doesn't work...


Posted by northcode in SWF Studio V3 on Jun 09 2008, 04:07 pm

What comes out in the SWF Studio Trace Tab when you do this?

var r = ssCore.Shell.open({path:"startdir://thefile.pdf"});
ssDebug.trace(r.Error.description);


Posted by angela in SWF Studio V3 on Jun 10 2008, 05:29 am

Hey Tim,

The code ssCore.Shell.open({path:"startdir://thefile.pdf"}) didn't work because I was working within a shared folder. Testing out of that folder it works perfectly, but I've been testing this other with the prompt window and it doesn't; it always jump to the prompt window:

on (release) {
var r = ssCore.Shell.getDefaultApplication({extension:"pdf"});

if (r.result != undefined && r.result != "") {

ssCore.Shell.open({path:"startdir://guia_tarjeta_tcpip.pdf"});

} else {

ssCore.App.showMsgBox({prompt:"No tiene instalado Acrobat Reader"});

}
}


Posted by northcode in SWF Studio V3 on Jun 10 2008, 09:23 am

Every call to an ssCore method returns an error code and description to help you (and us) figure out what's going on. But you have to use them :) What does ssDebug.trace(r.Error.description) spit out if you put it right after the call to Shell.getDefaultApplication?


Posted by mbd in SWF Studio V3 on Jun 10 2008, 10:47 am

Have you enabled synchronous commands? Take a look at the FAQ link in my signature.


Posted by angela in SWF Studio V3 on Jun 10 2008, 12:33 pm

Yes, that was the key, the synchronous commands, well, this one:
ssDefaults.synchronousCommands = true;

Sorry, I didn't know about these commands.
Thanks so much to all of you, Derek, Tim and Pompeyd, you are the best, so helpful and patient with me...

I think everything is alright by now. You don't know how much this means to me in order to give my client a solution.

Thanks again.

Angela


Posted by jeremiah2329 in SWF Studio V3 on Jun 12 2008, 02:13 pm

I'm looking to do the same thing as Angela. I used the code that Tim suggested (with the change that when no pdf reader was found it sent the user to a different scene that would have the pdf information). I was being taken to the get pdf scene even though I have a pdf reader installed. When I enabled synchronous commands, nothing happened - that is, when I click the button, it does nothing.

Here is the code that I'm using (just a compilation of the above suggestions):

on (release) {
   ssDefaults.synchronousCommands = true;
   var r = ssCore.Shell.getDefaultApplication({extension:"pdf"});

if (r.result != undefined && r.result != "")
{
   // a PDF viewer is installed, open the PDF
   ssCore.Shell.open({path:"startdir://neoprism_application_notes.pdf.pdf"});
}
else
{
   // run the Adobe Acrobat Reader setup 
   gotoAndPlay("GetPdf", 1);

}
}


Posted by mbd in SWF Studio V3 on Jun 12 2008, 02:31 pm

Please use the error information that you are being given by the SWF Studio API. If you just check for properties to be undefined or not you aren't using the API to its fullest.

Place this in the main timeline (or in your document class in AS3):

ssCore.init();
ssDefaults.synchronousCommands = true;

You can enable/disable ssDefaults.synchronousCommands at any time, but it is a global setting and doesn't need to be set everytime you issue a command.

Change your code to the code below and make sure you enable the debug option in the Output tab of SWF Studio. Then make sure SWF Studio is open and displaying the Trace tab when you launch your application.

on (release) {
   var r = ssCore.Shell.getDefaultApplication({extension:"pdf"});

   if (r.result)
   {
      // a PDF viewer is installed, open the PDF
      ssDebug.trace("Open the PDF");
      ssCore.Shell.open({path:"startdir://neoprism_application_notes.pdf.pdf"});
   }
   else
   {
      // run the Adobe Acrobat Reader setup
      if (!r.success) ssDebug.trace("ERROR: "+r.Error.description);
      else gotoAndPlay("GetPdf", 1);
   }
}

Are you publishing your SWF for Flash player 8?


Posted by jeremiah2329 in SWF Studio V3 on Jun 12 2008, 02:58 pm


QUOTE:
Are you publishing your SWF for Flash player 8?

I had been publishing to Flash Player 9. Is it necessary to go back to 8? or can it be left at 9?


Posted by jeremiah2329 in SWF Studio V3 on Jun 12 2008, 03:13 pm

When I used your suggested code, it worked fine on my computer. It opened the pdf and the trace simply returned the "open pdf" message.

I tried running the exe on a computer without a pdf reader, and it did not open the file. The problem is, I don't have swf studio installed on that computer, so I couldn't get the trace information. Can you suggest a method for testing the no pdf reader aspect of this function?


Posted by mbd in SWF Studio V3 on Jun 12 2008, 03:17 pm

Just change ssDebug.trace to ssDebug.msgBox to display a messagebox.

You don't have to go down to Flash player 8, I just wanted to make sure you weren't publishing for an earlier Flash player, since synchronous commands will only work for SWFs published for Flash player 8 or later.


Posted by angela in SWF Studio V3 on Jun 12 2008, 03:29 pm

I don't know, but could it be because the pdf file ends with .pdf.pdf?


Posted by jeremiah2329 in SWF Studio V3 on Jun 12 2008, 03:33 pm

When I ran the exe on the test computer without a pdf reader that message box said: "No application association was found for the specific extension" - but it did not go to my "GetPdf" scene.

-Ron


Posted by mbd in SWF Studio V3 on Jun 12 2008, 03:40 pm

I edited the code a little quick. Here's a better version:
on (release) {
   var r = ssCore.Shell.getDefaultApplication({extension:"pdf"});

   if (r.success)
   {
      // a PDF viewer is installed, open the PDF
      ssDebug.msgBox("Open the PDF");
      ssCore.Shell.open({path:"startdir://neoprism_application_notes.pdf.pdf"});
   }
   else
   {
      // run the Adobe Acrobat Reader setup
      ssDebug.msgBox("ERROR: "+r.Error.description);
      
      gotoAndPlay("GetPdf", 1);
   }
}


Posted by jeremiah2329 in SWF Studio V3 on Jun 12 2008, 03:46 pm

Thanks Derek!

That worked perfectly.

Just one small question. Is there any need to remove the debugging information from the action script? Or should I just uncheck the debugging box in SWF Studio?


Posted by mbd in SWF Studio V3 on Jun 12 2008, 03:49 pm

You can leave them in there if you want. Unchecking the debug option disables ssDebug, so any methods called on it won't do anything.