Open PDF and Files with AS3 from projector
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Open PDF and Files with AS3 from projector

  1. #1
    Senior Member
    Join Date
    Aug 2001
    Location
    New York City
    Posts
    409

    Open PDF and Files with AS3 from projector

    Hi -

    I have used M-Projector, North Code, and ZINC in the past, but I haven't had the need to create a standalone in a while. Since then CS4 and AS3 and I tried using the old fire-it-up which allows you to launch, print and save files. It works in AS2 but not my AS3 project.

    Does anyone have a simple Cross Platform suggestion ? All I want to do it Launch Files and Keep it simple. I don't really want to have to learn an API from some of the great 3rd party tools out there.

    Any Suggestions to perform this simple task ?
    Thanks!

  2. #2
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Ottawa
    Posts
    3,697

  3. #3
    Senior Member
    Join Date
    Aug 2001
    Location
    New York City
    Posts
    409
    Thanks NorthCode !
    I actually remember this thread from a while back. I will use it now since this is all I want to do.

    However... Will this work using AS3 ?

  4. #4
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Ottawa
    Posts
    3,697
    The EXEC fscommand works in all versions of Flash as long as you're creating a projector (it won't work from a SWF).

  5. #5
    Senior Member
    Join Date
    Aug 2001
    Location
    New York City
    Posts
    409
    Hi NorthCode -
    I tried the PROXY and the BAT File recipe as you suggested and it's not opening a file. Here's what my file structure looks like:
    FScommand (folder)
    - invoke.exe
    - launchTest.BAT
    - launchTest.exe


    Outside of the FScommand folder I have this:
    files (folder)
    launchtest.pdf

    And this :
    launchAS3.exe (The Projector File)

    inside my BAT file I have this line:

    invoke.exe open \files\launchTest.pdf

    And I just changed the name of the PROXY.EXE to:
    launchTest.exe

    Anything else I can do ? I uploaded my .fla and the files, without the Projector (or it would have been to large for FlashKit) Maybe you can take a look or a test? thanks so much.
    Attached Files Attached Files

  6. #6
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Ottawa
    Posts
    3,697
    Your problem isn't with proxy, invoke or your BAT file. If you put a trace statement in the launch() function you'll see that it isn't getting called! That's the problem.

  7. #7
    Senior Member
    Join Date
    Aug 2001
    Location
    New York City
    Posts
    409
    Hi Northcode -

    I feel like I am close to this working. Here's my AS3 code and it DOES CALL THE function and a trace:
    Code:
    function launch(event:MouseEvent):void {
    
    	fscommand("exec", "launchTest.exe");
    	trace("I am calling the function now");
    
    }
    launchButton.addEventListener(MouseEvent.CLICK, launch);
    
    launchButton.buttonMode=true;
    Am I calling the calling file ? Not sure, but the function seems to be working... any other suggestions? Thank you so much for your help

  8. #8
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Ottawa
    Posts
    3,697
    Odd, when I published your FLA to an EXE last time it didn't work, now it does. I replaced what you had with the latest versions of invoke.exe and proxy.exe and changed the path in the BAT file from \files\launchTest.pdf to ..\files\launchTest.pdf and it's working fine for me. If you grab steve1312_proxy2.zip (2.34 MB) I've included everything, including a compiler version of launchAS3.exe.

  9. #9
    Senior Member
    Join Date
    Aug 2001
    Location
    New York City
    Posts
    409
    Thanks Northcode. Works like a charm !
    You are a master ! thank you.

  10. #10
    Registered User
    Join Date
    Apr 2011
    Posts
    2
    Hi Tim,

    Do you have any idea how to handle the document (doc, pdf, etc) in MAC OS (intel based MAC OS 10.5 or above)?
    We are using the getURL and placed the document fscommand folder. Some MAC machines not opening the documents.
    I am using flash player 9.0 projector file.
    Please help.

  11. #11
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Ottawa
    Posts
    3,697
    AppleScript is the simplest solution for the Mac and you can basically do the same thing. Create one AppleScript for each file you want to open and then use fsommand("exec", "file1.app") where file1.app is a compiled AppleScript that opens a PDF file.

    The key difference between OSX and Windows is where the fscommand folder goes. On windows it goes in the same folder as your EXE. On OSX it has to be put inside the projector's application bundle in MyApp.app -> Contents -> MacOS, which is where the Flash player binary actually lives.
    When your swf2exe tool just HAS to work
    there's only one choice... SWF Studio

  12. #12
    Junior Member
    Join Date
    Mar 2012
    Posts
    1
    thx Tim , you're the man

  13. #13
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,926
    NC,

    I'm working on a hybrid cd (and web) project and have the getURL working on the web-side, the bat files working on the PC side and just need to get the applescript files compiled. Do you know of any way to do this on a PC?

    Also, what is the correct syntax within the applescript file? If I have to send it to my client to compile on his Mac, I'd like to only have to do it once.

    Do I have it call the Word file directly:
    Code:
    tell application "Microsoft Word"
        activate
        open "DNALab.doc"
    end tell
    Save this as DNALab.app and have as3 call:
    Code:
    fscommand("exec", "DNALab.app");
    Thanks!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  14. #14
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Ottawa
    Posts
    3,697
    As far as I know there's no way to compile an AppleScript from a PC, you'll need a Mac to do that.

    If you know where the file is going to be on the CD and you can set the CD name then you can use a simple script like this one.

    Code:
    tell application "Finder"
       activate
       select file "file.doc" of folder "fscommand" of disk "CDNAME"
       open selection
    end tell
    If you can't control any of that, then you have to resort to something a little more complicated that locates the file you want to open from a location relative to your application. I've posted this before, but I'll save you the trouble of hunting it down.

    Code:
    --set the name of the file to open 
    
    property fileName : "homepage.html"
    
    --get the path to the containing folder 
    
    set myPath to (path to me as string)
    set AppleScript's text item delimiters to ":"
    
    set the parentFolder to 
    	((text items 1 thru -2 of myPath) & "") as string
    
    set AppleScript's text item delimiters to ""
    
    -- find the flash file 
    
    try
    	set targetFile to alias (the parentFolder & fileName)
    on error
    	--ie if there's no  file here by this name, it will quit. 
    	return quit
    end try
    
    -- open the file 
    
    tell application "Finder"
    	open file targetFile
    end tell
    If you're using CS3 (or newer) you need to know that the FSCommand folder is now INSIDE your .app file and not an external folder as it was in versions before that. This makes targeting files from AppleScript a little trickier because every reference you make is relative to the fscommand folder, where the AppliScript has to be so you can EXEC it.
    Last edited by Northcode; 07-03-2012 at 03:42 AM.
    When your swf2exe tool just HAS to work
    there's only one choice... SWF Studio

  15. #15
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,926
    Cool, I got a buddy with a mac to make the scpt files for me. I published the Mac projector and am getting ready to send it to the client to review. Do I have to drop the fscommand folder inside the start.app folder or the Contents folder?

    Thanks!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  16. #16
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Ottawa
    Posts
    3,697
    The fscommand folder has to be in the same folder as the "Flash Player" file inside the app bundle so it should be in...

    TheApp.app\Contents\MacOS

    So the final resting place for your AppleScript should be...

    TheApp.app\Contents\MacOS\fscommand\script.app
    When your swf2exe tool just HAS to work
    there's only one choice... SWF Studio

  17. #17
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,926
    Excellent! Thanks!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  18. #18
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,926
    Northcode...hoping you can give me a little more direction here.

    So, I've got all the .app and .exe and .bat files for each one of the documents I need to open (39 total).

    Here's how I have the files set up on the CD:
    ROOT
    start.exe
    section1.swf - this is an animation that loads and plays as part of the CD
    fscommand (FOLDER)
    all the .exe, .bat and target files to be opened

    start.app (FOLDER)
    Contents (FOLDER)
    MacOS (FOLDER)
    section1.swf
    fscommand (FOLDER)
    all the .app and target files to be opened

    The program launches fine on both platforms. The section1.swf takes longer to load and play on the Mac, but it does work (might just be the machine speed). On the PC, clicking on the buttons to open the documents works, but they ALL open the first document. On the Mac side, nothing opens when you click any of the document links...

    Here's the code I'm using:

    Code:
    switch (this[event.target.name])  //when I trace this, it gives me null, but samp1.doc opens
    	//switch (event.target.name) //when I trace this, it gives me the correct button name, but no documents open
    	{
    		case b1_mc :
    			if (platform == "WIN")
    			{
    				fscommand("exec", "samp1.exe");
    			break;
    			}
    			else
    			{
    				fscommand("exec", "samp1");
    			break;
    			}
    		case b2_mc :
    			if (platform == "WIN")
    			{
    				fscommand("exec", "samp2.exe");
    			break;
    			}
    			else
    			{
    				fscommand("exec", "samp2");
    			break;
    			}
                }

    Any help you can give me would be much appreciated. If you want, I'm glad to upload the code, files, package, etc. for you to grab and take a look at. I'm using CS6, but can save down to a previous version.

    Thanks!!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  19. #19
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,926
    Alright! Got that figured out. Turns out it was a nesting issue. This worked fine when I had the buttons on the stage (and used this[event.target.name] and no quotes around the button names in the switch statement), but, when I put them in a nested clip, I had to use event.target.name and add the quotes around the button names...strange, but it works now.

    Now, my only issue is that none of the documents open on the Mac side...hmmm....more testing...

    Let me know if anything jumps out at anyone about my folder structure....since I have the Mac files in the start.app folder, do I need to include that in my .app files somewhere?? Instead of this:

    PHP Code:
    tell application "Finder"
       
    activate
       select file 
    "file.doc" of folder "fscommand" of disk "CDNAME"
       
    open selection
    end tell 
    does it need to say something like:

    PHP Code:
    tell application "Finder"
       
    activate
       select file 
    "file.doc" of folder "fscommand" of folder "start.app" of disk "CDNAME"
       
    open selection
    end tell 
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  20. #20
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,926
    Northcode,
    Sent you a PM about a problem I'm still having with this. Would really appreciate it if you could take a few minutes to look at it...if not, I understand, I know you're busy.
    Thanks!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com