PDA

View Full Version : Open Excel File NOT using GetURL


iiSwanSongii
08-20-2010, 08:36 PM
I have used this site many times and am so grateful to all the people who assist. This is such a great resource! Today, I came across something that seems so simple, I'm hoping it belongs in this Category of 'simple stuff'.

I'm working on a CD Flash Project.

I have a 'main' flash file that pulls sub pages that are 'swfs' into it.
I publish the main as an exe.

In one of the swfs that is pulled into the main file, I have a link that is setup to 'getURL' of an excel file that is in a specific folder. Well, the client doesn't like that the excel file opens in a browser window. They would rather it open in the actual excel program.

I'm prepared to explain to them that "letting it open in a browser would assist in better compatibility if the user doesn't have excel" if I cannot find this solution.

I found flashgeek.exe and writing .bat files, but flashgeek only works within an exe published file which I think is the reason my linking isn't working because the code is in the swf sub page. As for the .bat, I don't like that a small dos window would open and close. They might think something is wrong.

That being said, knowing about my file setup, is there any suggestions for me out there other than what I've tried to open an excel file from my swf file using any other actionscript than getURL?

Any help is extremely appreciated!

Thank you kindly!

northcode
08-21-2010, 05:13 AM
If the user doesn't have Excel install then you're not going to have the right stuff installed to open the XLS file in the browser either. If they have the Excel viewer installed (but not Excel itself) it might work in a browser (haven't tried it) but it will work from a BAT file.

You're going to HAVE to use an EXE instead of a SWF if you want to use the EXEC fscommand because EXEC only works if you publish your FLA to EXE format. It's also the only way that I'm aware of to open another file / application without using getURL.

If you don't like the ugly DOS box, try my FREE proxy utility (http://www.northcode.com/blog.php/2007/08/07/Conquering-FSCommand-EXEC-Part-1-Proxy). If you read the other posts on my blog you'll also find some other useful free tools for working with Flash projector files.

The ultimate solution isn't free but it will allow you give your Flash based CD projects a huge boost... SWF Studio (http://www.northcode.com):)

modpod77
08-25-2010, 04:18 PM
I had the same problem with you then I came to this topic :D THank you so much fir sharing this useful information!

iiSwanSongii
08-27-2010, 08:54 PM
Thank you Northcode for responding...I found another solution that I really thought would work since it was free from 'flashgeek'. Here is the tutorial on how to use it: wwwdotopendbdotnet/element/216.php

Now the problem is that for me on a PC (tested the cd on 3 different pcs mind you) everything is successful!. However, when I gave that same cd to my client, they said that they absolutely cannot click on any of my links to excel or powerpoint. They just do not work. Also, I had another person with a Mac, and they sent me a screenshot of what they are prompted with when trying to click on one of the excel and powerpoint links:

www-dot-intotheether-dot-net/screenshotmac.jpg

Has anyone had issues with this flashgeek script?

Any other advice would be greatly appreciated!

Thank you!

northcode
08-28-2010, 02:00 PM
The solution from flashgeek is ancient and based on using Flash 5 (if I'm remembering it correctly) which won't work with newer versions of Flash will fail spectacularly with CS3, CS4 and CS5. Neither the flashgeek solution nor mine will work on a Mac, they are for Windows only. On a Mac you'll have to use AppleScript to open files. I wrote a SmartExec function a few years back that lets you put one call in that works on both platforms, if you have the right EXE/AppleScript to handle the details.

----- Old Post -----

I've posted this function here a few times, it may simplify your job of opening PDF files a bit. Instead of calling fscommad "exec" everywhere you want to open a file and worrying about which platform you're on, you replace those calls with calls to SmartExec.


function SmartExec(target)
{
platform = substring(getVersion(), 1,3);

if (platform == "WIN")
{
// we're running on Windows, target an EXE file
fscommand("exec", target + ".exe");
}
else
{
// we're running on a MAC, target an AppleScript file
fscommand("exec", target + "_script");
}
}


EXEC only works with executable files. In Windows that means EXE, COM and BAT files. On the MAC that's applescripts, applications and probably some other stuff I'm unaware of ;)

The trick to making this work in Windows is to write a BAT file called "thefile.bat" that has the command you need to open your PDF file (like "start thefile.pdf") then rename my proxy.exe utility to thefile.exe and call that using the SmartExec function like this: SmartExec("thefile").

For the MAC, you just create an applescript called thefile_script with the commands to open the PDF file and the same call to SmartExec will get the job done on either platform.

All the executable files, BAT files, AppleScripts go in the FSCommand folder. The files you want to open can go in there too if you want to make writing the scripts and BAT files easier on yourself.

You might want to check out Conquering-FSCommand EXEC Part-1 : Proxy (http://www.northcode.com/blog.php/2007/08/07/Conquering-FSCommand-EXEC-Part-1-Proxy) for a FREE utility I wrote that will let you run BAT files from Flash and avoid the ugly DOS box. There was a big discussion about it (and some other utilities I wrote) in http://www.flashkit.com/board/showthread.php?threadid=519274.

iiSwanSongii
08-29-2010, 01:05 PM
Thank you so much Northcode!
Your assistance has helped me tremendously. I am going to give all of it a try today and post my results.

I looked through the links you provided, and the only reference I saw for how the applescript is supposed to be written is this:

here is my applescript:
tell application "Finder"
activate
select file "1.doc" of disk "Turnarond Solutions 5W's Method"
open selection
end tell

I was hoping you could confirm that this is the way its 'supposed' to be written. Do I have to put the name of the disc in the script? Seems like this was added for this particular persons application. Might not be necessary for what I'm using it for.

iiSwanSongii
08-30-2010, 01:26 AM
function SmartExec(target)
{
platform = substring(getVersion(), 1,3);

if (platform == "WIN")
{
// we're running on Windows, target an EXE file
fscommand("exec", target + ".exe");
}
else
{
// we're running on a MAC, target an AppleScript file
fscommand("exec", target + "_script");
}
}



NorthCode! Urgent questiont...in attempting to implement the help you gave me...i am developing in AS2 and it needs to stay in as2 because of some other code that i implemented for transitions etc.

this code is AS3 isn't it? is there ANY equivalent for AS2????

Here is the error i get within flash when i test for script errors:

"There is no method with the name 'slice'."

thoughts?

northcode
08-30-2010, 03:45 AM
The code is AS2. There's no call to "slice" in the code I gave you. There is a String.slice method that does what substring does, but I didn't use it.

iiSwanSongii
08-30-2010, 04:17 AM
Northcode...i admit i didn't read the link to the long thread thoroughly enough...

i just found this:

function SmartExec(file)
{
platform = substring($version, 0, 3);
if (platform == "WIN") {
fscommnd("exec", file+".exe");
} else {
fscommand("exec", file+".app");
}
}


haven't tested but will.

thank you. just in panic mode at the moment, this whole thing is due end of day tomorrow! wish me luck. *gulp*

northcode
08-30-2010, 05:31 AM
There are ways to make the AppleScript work from any CD with any name but it makes the script more complicated. If you know the name of the CD you're creating in advance then that makes life a bit easier. That's why it was done that way.

I'll usually around during normal business hours (EST in Canada) and often longer :) If you get "panicky" or stuck on something give me a shout and I'll see if I can help...

iiSwanSongii
08-30-2010, 03:34 PM
2:05pm EST
Well, as of rigt now, we determined that the presentation fla NEEDS to be published on a mac in order to work.

The final step is getting the applescript to work. They setup where I could remote desktop into their mac, and take a look at what the apple script is doing.

I have the normal edited script:


tell application "Finder"
activate
select file "Figure1.xls" of folder"../subs/charts"
open selection
end tell


WhenI try to test the applescript file (by hitting 'run' within script editor) it cannot find the file. in normal programming terms my paths are correct based on where these applescripts reside (inside the fscommand folder). Going back one, there is a 'subs' folder, then a 'charts' folder with this 'figure1.xls' file in it.

it says 'finder got an error: can't get folder "../subs/charts"

thoughts?

northcode
08-30-2010, 06:47 PM
Here's a script to open your file using the containing folder (of the script) to provide the location reference. Put the script and the file you want to open in the fscommand folder and try this...


--set the name of the file to open

property fileName : "Figure1.xls"

--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

iiSwanSongii
08-30-2010, 07:17 PM
Northcode. you are a lifesaver. I only wish I could help you someday in return. That is how much you have truly helped me with this. This code worked like a charm and im' now in the process of updating all of my code. I'm just going to move all of my excel and powerpoints into the fscommand folder and leave it at that.
don't want to mess arround with paths at this point

northcode
08-30-2010, 11:03 PM
Glad I could help ;)

dontstopdreaming
07-30-2011, 02:45 AM
Hi Northcode

Please can you help me out. Been banging my head for ages trying to figure this out. Your responses have been amazing. Managed to get everything working on the PC side of the CDROM I am creating.

Weirdly on the Mac Projector when the button is pressed nothing happens. Not sure if me code is slightly wrong here for AS3.

2x buttons loading 2 x excel files namely Locator.xls and Successful.xls

// ACTION SCRIPT 3 code loads perfectly on pc side when I call a bat file but not with a app file.

assessment.addEventListener(MouseEvent.CLICK, locator);
function locator(event:Event):void
{
fscommand("exec","Locator.app");

questionare.addEventListener(MouseEvent.CLICK, question);
function question(event:Event):void
{
fscommand("exec","Successful.app");
}


// APPLESCRIPT from script editor:
Saved file 1 as Locator.app and file 2 as Successful.app
The script file below works perfectly when the .app file is pressed and loads the file. However it doesnít load from within the mac projector file. Changed this for the second file called Successful.xls too.

--set the name of the file to open

property fileName : "Locator.xls"

--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

PLEASE HELP so stuck here been banging my head for days trying to figure it out.

Thanks
Colin
:D

northcode
07-30-2011, 03:13 AM
On the MAC, since CS3, the fscommand folder doesn't go beside the app, it's INSIDE the projector. On a MAC, applications are actually folders (application bundles) and you can modify their contents in Finder just like any other folder. If your projector is called "MyApp" then you need to open it by right clicking on it and then put your fscommand folder in MyApp.app/Contents/MacOS/fscommand.

dontstopdreaming
07-30-2011, 01:08 PM
HI Northcode

Thanks for the Advice. Unfortunately this is still not working.
I saved my application file and the excel files in the packaged contents of the projector in:
ChangeCycleMAC.app/Contents/MacOS/fscommand/Locator.app

ChangeCycleMAC.app is my projector file


>> In Script Editor
I have the following from your earlier code: and saved as an APPLICATION (not script, application bundle or script bundle) This application loads the excel file when clicked.

--set the name of the file to open

property fileName : "Locator.xls"

--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


On the Flash side I changed to the following in the actionscript:


assessment.addEventListener(MouseEvent.CLICK, locator);

function locator(event:Event):void
{
fscommand("exec","ChangeCycleMAC.app/Contents/MacOS/fscommand/Locator.app");
}



Thank you so MUCH ! you guys are geniuses on here. Donít know how you find out this information.
:)

northcode
07-31-2011, 03:05 AM
The EXEC command doesn't change, just where you put the files.

So this is wrong...


fscommand("exec","ChangeCycleMAC.app/Contents/MacOS/fscommand/Locator.app");


And this is the correct way to do it...


fscommand("exec","Locator.app");

dontstopdreaming
07-31-2011, 09:11 PM
Thanks for all your help Northcode..

Unfortunately it still is not working. We might build the contents into the flash projector. Would just be very interresting to know why it didn't work if you have any ideas for the future.

All the best

Colin

northcode
08-01-2011, 12:31 AM
Send email to [email protected] and I'll reply with a simple example that launches a script to open a PDF or a URL or something from a Mac projector. It won't be until later tonight though, or possibly tomorrow.

Just to make sure... you're using AS3 right?

What version of Flash do you need this done in? I have everything from 8 to CS 5.5 (except CS5, I skipped that donkey).