Open External Files in Native App from Flash Projector

Posted on: April 18th, 2012 by Edward 10 Comments

 

This post will show you how to open an external file in its native application from a Flash projector file. Of course, this can only work if you or your end-user has the appropriate application installed for the file to be opened or you’ll receive an error or depending on your OS, nothing will happen at all.

***This post assumes that you are going to have a Flash projector file and resource files on a CD/DVD ROM that a end-user must be able to access from the disc…if this is not your scenario, you can still continue reading…

Although there are other ways of doing this, the technique I post here is a non-technical solution and voodoo magic as far as the ActionScript Geekdom is concerned…but we’ll try not to let that bother us for the moment…but this technique is useful because it will allow the file to open from the projector WITHOUT the Windows Command Prompt…so it will appear to be a seamless process.

The first thing we need is the file that will actually do the work for us…a small (smart) little program from NorthCode called “proxy.exe” and about 52KB in file size. This program has been around since Flash MX and still gets the job done today…and as of April 2012 can still be downloaded at: http://www.northcode.com/blog.php/2007/08/07/Conquering-FSCommand-EXEC-Part-1-Proxy

Now, if the link is no longer valid, just Google “northcode proxy exe” and you should be able to get it.

Once you’ve got the proxy.exe file, you need to create a folder “in the folder” where your Flash projector will be published named “fscommand”—Flash ActionScript fscommand will only open a file if it’s in a folder with that name.

Next, you want to drag a copy of “proxy.exe” to the “fscommand” folder.

Now, drag a copy of the file you want Flash to open in the “fscommand” folder—for instance a PDF document or a Microsoft Office file…for the sake of this post, let’s say our file is called “Product_Instructions.pdf”…I’d recommend replacing any spaces in the filename with a dash or underscore…not required, but a good practice…

Now our fscommand folder has “proxy.exe” and “Product_instructions.pdf” inside of it…

Next, we need to make “proxey.exe” open our PDF…in order to do this, we need a “.bat” (batch) file with instructions…I know, this is starting to get complicated…believe me it’s not…let me add a bit more complexity to it and then you’ll have that “V-8” moment, just bare with me…

The thing about proxy.exe is that it looks for a .bat file with the same name it has, and then it performs the command in that file…if that command is to open a PDF than that’s what it does. So, keeping this in mind, we will:

  • rename proxy.exe to open_my_pdf.exe (or whatever you want to call it)
  • then open Notepad (or any text editor) and put in this instruction…
    START Product_instructions.pdf (which is our PDF document)
  • then save the Notepad file as…remember, the same name you changed proxey.exe to…but with a “.bat” file extension…so we will be saving “open_my_pdf.bat”
    IMPORTANT: make sure “All files” is selected in the Notepad “Save as type” dropdown or you’ll end up with “open_my_pdf.bat.txt”

That’s it…we now have in our fscommand folder three files…open_my_pdf.exe…open_my_pdf.bat…and our Product_instructions.pdf. Now, if you haven’t had that V-8 moment yet, then I’m afraid it’s not going to happen for you…

At this point we only need to create a button in Flash that will open our “open_my_pdf.exe”…

Here is AS3 code:

myButton.addEventListener(MouseEvent.CLICK, openPDF);
function openPDF (e:MouseEvent):void {
  fscommand("exec","open_my_pdf.exe");
}

…”myButton” is the instance name of the button and “openPDF” is the function name…
This technique will open any file type as long as the application to open it is installed on the computer requesting to open the file.

And as I said, this is a non-technical technique…and it can be used to open multiple documents from the same CD/DVD ROM project as long as all of the names (file names, variable names, etc.) are unique.

10 Responses

  1. montag says:

    can i use this method to launch a .swf or another projector file?

    • Edward says:

      Montag,
      You only need the myButton code example to open an EXE (projector) file…however, a SWF movie is a different story. A SWF movie needs to be embedded in an HTML page…and then that HTML page can be opened with a button in a popup window (the same width and height of your SWF movie).

      • montag says:

        Thanks Edward,

        not sure what ‘myButton’ code is. am using thie code on frame

        function launch(event:MouseEvent):void {

        fscommand(“exec”, “bcs_TEST.exe”);

        }
        BCS_button.addEventListener(MouseEvent.CLICK, launch);

        BCS_button.buttonMode=true;
        }

        Is this code you are talking about? Also. I have fscommand folder with contents

        bcs_TEST.bat
        bcs_TEST.exe (projector file)

        in it. bat file code is

        start bcs_TEST.exe

        This is not working. Unfortunately I am not a developer or coder and I have never used AS3 before so not doubt there are many mistakes. I would greatly appreciate any assistance you could offer.

        Montag

        • Edward says:

          Montag, the myButton code was the code in the tutorial above:
          myButton.addEventListener(MouseEvent.CLICK, openPDF);
          function openPDF (e:MouseEvent):void {
          fscommand(“exec”,”open_my_pdf.exe”);
          }

          So, in your case, all you need to do is place your EXE file in the fscommand folder and use this code provided your button has an instance name of BSC_button and your EXE is named bsc_TEST:

          BSC_button.addEventListener(MouseEvent.CLICK, openEXE);
          function openEXE (e:MouseEvent):void {
          fscommand(“exec”,”bsc_TEST.exe”);
          }

          Since you’re opening an EXE, you don’t need the BAT file.

          This should work for you…good luck.

          • montag says:

            Good morning Edward,

            Thanks for the code. I pasted the code you sent

            BSC_button.addEventListener(MouseEvent.CLICK, openEXE);
            function openEXE (e:MouseEvent):void {
            fscommand(“exec”,”bsc_TEST.exe”);
            }

            into a frame, top layer (called ‘script’}

            When I publish royal_TEST projector with button ‘BCS_button’ in it, I get these output errors…

            Scene 1, Layer ‘script’, Frame 1, Line 3 1093: Syntax error.
            Scene 1, Layer ‘script’, Frame 1, Line 3 1093: Syntax error.
            Scene 1, Layer ‘script’, Frame 1, Line 3 1093: Syntax error.
            Scene 1, Layer ‘script’, Frame 1, Line 3 1093: Syntax error.

            Having never used AS5 before I’m unsure what this means let alone how to fix it.

            Thanks again, Montag

          • Edward says:

            Montag,
            When you copied and pasted the code, Flash did not interpret the CURLY QUOTES as actual QUOTES…just delete the quotes (ALL) and use your keyboard to type in REAL QUOTES…

    • montag says:

      Edward, I think I must have done something really wrong. I used this code

      BCS_button.addEventListener(MouseEvent.CLICK, openEXE);
      function openEXE (e:MouseEvent):void (
      fscommand(“exec”,”bcs_TEST.exe”);
      )

      and I got these compiler errors

      Scene 1, Layer ‘script’, Frame 1, Line 2 1158: Syntax error: missing left brace ({) before the function body.
      Scene 1, Layer ‘script’, Frame 1, Line 3 1093: Syntax error.
      Scene 1, Layer ‘script’, Frame 1, Line 3 1093: Syntax error.
      Scene 1, Layer ‘script’, Frame 1, Line 3 1093: Syntax error.
      Scene 1, Layer ‘script’, Frame 1, Line 3 1093: Syntax error.
      Scene 1, Layer ‘script’, Frame 1, Line 4 1084: Syntax error: expecting identifier before rightparen.

      Montag

  2. Edward says:

    Nasodan,
    I used this technique with Flash CS5 and Flash Player 10…not sure why you would be having problems…but I’ll try to look into it…and let me know if you find a solution as well.

    • nasodan says:

      Thanks a lot for replay,
      i want explain better my question.
      The problem is when I try to open a file (pdf) from mac exported projector, it crashes.
      The application works fine untill i try to open the file.
      Clicking on the button that call fscommand(“exec”. “myfile”), the app crashes.
      On PC works fine.
      I tried exporting both projector (.exe and .app) by Flash CS4, CS5 from Mac and Pc, but nothing.
      So i was forced to use CS3, and for this i was forced to put the fscommand folder in Contents->MacOS folder, etc. etc. 🙁
      That’s all
      Thanks

  3. nasodan says:

    I Ed,
    i just used this technique and works very well,
    but I found some problems on mac, after Flash CS3.
    I solved opening the mac projector (like a folder) and putting the FSCommand folder in Contents->MacOS folder, and exporting the projector from Flash CS3.
    The limitation is that you can’t use Flash player 10 APIs and later.
    If you know same workaroun is welcome
    Bye and thanks

Leave a Reply

You must be logged in to post a comment.